Skip to content

Instantly share code, notes, and snippets.

@Dowwie
Last active January 8, 2018 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dowwie/b30e14566fb1461fd964cf4e0793c2a0 to your computer and use it in GitHub Desktop.
Save Dowwie/b30e14566fb1461fd964cf4e0793c2a0 to your computer and use it in GitHub Desktop.
bench_maplit_hash.rs
#![feature(test)]
extern crate test;
#[macro_use] extern crate bencher;
#[macro_use] extern crate maplit;
use test::Bencher;
use std::collections::HashSet;
fn test_maplit() -> HashSet<&'static str> {
let a = hashset!{"a", "a", "a", "b", "c"};
a
}
fn test_stdlib() -> HashSet<&'static str> {
let b: HashSet<&'static str> = ["a", "a", "a", "b", "c"].iter().cloned().collect();
b
}
fn main() {
let a = test_maplit();
println!("{:?}", a);
let b = test_stdlib();
println!("{:?}", b);
}
#[bench]
fn bench_maplit(b: &mut Bencher) {
b.iter(|| test_maplit())
}
#[bench]
fn bench_stdlib(b: &mut Bencher) {
b.iter(|| test_stdlib())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment