Skip to content

Instantly share code, notes, and snippets.

@0xdeafbeef
Created February 8, 2026 14:59
Show Gist options
  • Select an option

  • Save 0xdeafbeef/2900b3a5219b30a78767c5a6423ea880 to your computer and use it in GitHub Desktop.

Select an option

Save 0xdeafbeef/2900b3a5219b30a78767c5a6423ea880 to your computer and use it in GitHub Desktop.
drop times
[package]
name = "drops"
version = "0.1.0"
edition = "2024"
[dependencies]
bumpalo = { version = "3.19.1", features = ["allocator-api2", "collections"] }
hashbrown = "0.16.1"
use bumpalo::Bump;
use bumpalo::collections::{String as BString, Vec as BVec};
use hashbrown::HashMap;
use std::fmt::Write;
use std::hint::black_box;
use std::time::Instant;
fn main() {
let n = 30_000;
let vlen = 500;
println!("running benchmarks... {} entries, {} len", n, vlen);
// --- standard heap ---
println!("--- std heap ---");
let t = Instant::now();
let mut map = HashMap::new();
for i in 0..n {
let k = format!("k{}", i);
let mut vec = Vec::with_capacity(vlen);
for j in 0..vlen {
vec.push(format!("v{}:{}", i, j));
}
map.insert(k, vec);
}
println!("build: {:?}", t.elapsed());
black_box(map.len());
let t = Instant::now();
map.clear();
println!("clear: {:?}", t.elapsed());
black_box(map.len());
let t = Instant::now();
drop(map);
println!("drop: {:?}", t.elapsed());
// --- std + bump ---
println!("\n--- std map + bump ---");
let b = Bump::new();
let t = Instant::now();
let mut map = HashMap::new();
for i in 0..n {
let mut k_str = BString::new_in(&b);
write!(k_str, "k{}", i).unwrap();
let k = k_str.into_bump_str();
let mut vec = BVec::with_capacity_in(vlen, &b);
for j in 0..vlen {
let mut v_str = BString::new_in(&b);
write!(v_str, "v{}:{}", i, j).unwrap();
vec.push(v_str.into_bump_str());
}
map.insert(k, vec);
}
println!("build: {:?}", t.elapsed());
black_box(map.len());
let t = Instant::now();
map.clear();
println!("clear: {:?}", t.elapsed());
let t = Instant::now();
drop(map);
println!("drop map: {:?}", t.elapsed());
drop(b);
// --- hashbrown + bump ---
println!("\n--- hashbrown + bump ---");
let b = Bump::new();
let t = Instant::now();
let mut map: HashMap<&str, BVec<&str>, _, _> = HashMap::with_capacity_in(n, &b);
for i in 0..n {
let mut s = BString::new_in(&b);
write!(s, "k{}", i).unwrap();
let key = s.into_bump_str();
let mut vals = BVec::with_capacity_in(vlen, &b);
for j in 0..vlen {
let mut s2 = BString::new_in(&b);
write!(s2, "v{}:{}", i, j).unwrap();
vals.push(s2.into_bump_str());
}
map.insert(key, vals);
}
println!("build: {:?}", t.elapsed());
black_box(map.len());
let t = Instant::now();
map.clear();
println!("clear: {:?}", t.elapsed());
let t = Instant::now();
drop(map);
println!("drop: {:?}", t.elapsed());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment