summaryrefslogtreecommitdiffhomepage
path: root/benchmarks
diff options
context:
space:
mode:
authorTyge Lovset <[email protected]>2021-11-03 23:15:59 +0100
committerTyge Lovset <[email protected]>2021-11-03 23:15:59 +0100
commitd25619e0d6ac9970c23610326285d549c266c7c8 (patch)
tree65130479d28acaea792f5ed01c5aa79ebed42d1d /benchmarks
parent85a7ff53750a55fee9a45083abb2f6daa5b19164 (diff)
downloadSTC-modified-d25619e0d6ac9970c23610326285d549c266c7c8.tar.gz
STC-modified-d25619e0d6ac9970c23610326285d549c266c7c8.zip
Renamed cnt_X_getmut() to cnt_X_get_mut().
Diffstat (limited to 'benchmarks')
-rw-r--r--benchmarks/rust_hashmap.rs89
1 files changed, 45 insertions, 44 deletions
diff --git a/benchmarks/rust_hashmap.rs b/benchmarks/rust_hashmap.rs
index d1372e8b..cd1f114e 100644
--- a/benchmarks/rust_hashmap.rs
+++ b/benchmarks/rust_hashmap.rs
@@ -1,44 +1,45 @@
-use std::time::{Instant};
-use std::io::Read;
-
-fn romu_rotl(val: u64, r: u32) -> u64
- { return (val << r) | (val >> (64 - r)); }
-
-fn romu_trio(s: &mut[u64]) -> u64 {
- let xp = s[0]; let yp = s[1]; let zp = s[2];
- s[0] = 15241094284759029579 * zp;
- s[1] = yp - xp; s[1] = romu_rotl(s[1], 12);
- s[2] = zp - yp; s[2] = romu_rotl(s[2], 44);
- return xp;
-}
-
-fn main() {
- let n = 50_000_000; let mask = (1 << 25) - 1;
- let mut m = std::collections::HashMap::<u64, u64>::with_capacity(n);
- let mut rng: [u64; 3] = [1872361123, 123879177, 87739234];
- println!("Rust HashMap n = {}, mask = {:#x}", n, mask);
- let now = Instant::now();
- for _i in 0..n {
- let key: u64 = romu_trio(&mut rng) & mask;
- *m.entry(key).or_insert(0) += 1;
- }
- println!("insert : {}ms \tsize : {}", now.elapsed().as_millis(), m.len());
- let now = Instant::now();
- let mut sum = 0;
- for i in 0..mask + 1 { if m.contains_key(&i) { sum += 1; }}
- println!("lookup : {}ms \tsum : {}", now.elapsed().as_millis(), sum);
-
- let now = Instant::now();
- let mut sum = 0;
- for (_, value) in &m { sum += value; }
- println!("iterate : {}ms \tsum : {}", now.elapsed().as_millis(), sum);
-
- let mut rng: [u64; 3] = [1872361123, 123879177, 87739234];
- let now = Instant::now();
- for _ in 0..n {
- let key: u64 = romu_trio(&mut rng) & mask;
- m.remove(&key);
- }
- println!("remove : {}ms \tsize : {}", now.elapsed().as_millis(), m.len());
- println!("press a key:"); std::io::stdin().bytes().next();
-} \ No newline at end of file
+use std::time::{Instant};
+use std::io::Read;
+
+fn romu_rotl(val: u64, r: u32) -> u64
+ { return (val << r) | (val >> (64 - r)); }
+
+fn romu_trio(s: &mut[u64]) -> u64 {
+ let xp = s[0]; let yp = s[1]; let zp = s[2];
+ s[0] = 15241094284759029579 * zp;
+ s[1] = yp - xp; s[1] = romu_rotl(s[1], 12);
+ s[2] = zp - yp; s[2] = romu_rotl(s[2], 44);
+ return xp;
+}
+
+fn main() {
+ let n = 50_000_000; let mask = (1 << 25) - 1;
+ let mut m = std::collections::HashMap::<u64, u64>::with_capacity(n);
+ let mut rng: [u64; 3] = [1872361123, 123879177, 87739234];
+ println!("Rust HashMap n = {}, mask = {:#x}", n, mask);
+ let now = Instant::now();
+ for _i in 0..n {
+ let key: u64 = romu_trio(&mut rng) & mask;
+ *m.entry(key).or_insert(0) += 1;
+ }
+
+ println!("insert : {}ms \tsize : {}", now.elapsed().as_millis(), m.len());
+ let now = Instant::now();
+ let mut sum = 0;
+ for i in 0..mask + 1 { if m.contains_key(&i) { sum += 1; }}
+ println!("lookup : {}ms \tsum : {}", now.elapsed().as_millis(), sum);
+
+ let now = Instant::now();
+ let mut sum = 0;
+ for (_, value) in &m { sum += value; }
+ println!("iterate : {}ms \tsum : {}", now.elapsed().as_millis(), sum);
+
+ let mut rng: [u64; 3] = [1872361123, 123879177, 87739234];
+ let now = Instant::now();
+ for _ in 0..n {
+ let key: u64 = romu_trio(&mut rng) & mask;
+ m.remove(&key);
+ }
+ println!("remove : {}ms \tsize : {}", now.elapsed().as_millis(), m.len());
+ println!("press a key:"); std::io::stdin().bytes().next();
+}