Skip to content

Commit 052284c

Browse files
committed
Adding benchmarking to rust library.
git-svn-id: https://svn.rinrab.com/rinrab/xdigest/trunk@6673 0083e6b4-6090-234a-836e-88fcc467669c
1 parent bff1a6c commit 052284c

2 files changed

Lines changed: 65 additions & 1 deletion

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ rust-build:
287287
cd contrib/rust && cargo build
288288

289289
rust-test:
290-
cd contrib/rust && cargo test
290+
cd contrib/rust && cargo test && cargo bench
291291

292292
rust-package: rust-copydist
293293
cd contrib/rust/xdigest-src && cargo package
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* note: to compile this file, a nightly versin of rust compiler is required
3+
* because the whole bench feature is considered unstable. why? no idea.
4+
*/
5+
6+
#![feature(test)]
7+
extern crate test;
8+
9+
use xdigest::XDigest;
10+
11+
fn create_buf(buf: &mut [u8]) {
12+
let mut i = 0;
13+
let mut seed: u32 = 67;
14+
15+
while (i < buf.len()) {
16+
seed = (seed * 1103515245 + 12345) & 0xffffffff;
17+
buf[i] = (seed & 0xff) as u8;
18+
i += 1;
19+
}
20+
}
21+
22+
macro_rules! bench_update {
23+
(
24+
$init:expr,
25+
$name:ident
26+
) => {
27+
#[bench]
28+
fn $name(b: &mut test::Bencher) {
29+
let mut buf = [0u8; 1024 * 1024];
30+
let mut i = 0;
31+
let mut ctx = $init;
32+
33+
create_buf(&mut buf);
34+
35+
b.iter(|| {
36+
ctx.update(&buf);
37+
i += 1;
38+
});
39+
b.bytes = buf.len() as u64;
40+
41+
let _hash = ctx.finalise();
42+
}
43+
}
44+
}
45+
46+
bench_update!(
47+
xdigest::SHA256::new(),
48+
sha256
49+
);
50+
51+
bench_update!(
52+
xdigest::SHA512::new(),
53+
sha512
54+
);
55+
56+
bench_update!(
57+
xdigest::SHA1::new(),
58+
sha1
59+
);
60+
61+
bench_update!(
62+
xdigest::MD5::new(),
63+
md5
64+
);

0 commit comments

Comments
 (0)