...
这是2年前情况(tiny-keccack一直没有迭代), 我在跳板机上测试结论使用最新的sha3库,
修改tiny-keccak下comparison/Cargo.toml文件
代码块 |
---|
% git diff comparison/Cargo.toml
diff --git a/comparison/Cargo.toml b/comparison/Cargo.toml
index 1b88b6a..b0dd061 100644
--- a/comparison/Cargo.toml
+++ b/comparison/Cargo.toml
@@ -6,4 +6,4 @@ authors = ["debris <marek.kotewicz@gmail.com>"]
[dependencies]
tiny-keccak = { path = "../", features = ["sha3"] }
-sha3 = "0.8.2"
+sha3 = "0.10.0"
|
代码块 |
---|
+++ b/comparison/benches/sha3.rs
@@ -40,8 +40,8 @@ fn rust_crypto_sha3_256_input_32_bytes(b: &mut Bencher) {
b.iter(|| {
let mut sha3 = Sha3_256::default();
- sha3.input(&data);
- sha3.result();
+ sha3.update(&data);
+ sha3.finalize();
});
}
@@ -53,7 +53,7 @@ fn rust_crypto_sha3_256_input_4096_bytes(b: &mut Bencher) {
b.iter(|| {
let mut sha3 = Sha3_256::default();
- sha3.input(&data);
- sha3.result();
+ sha3.update(&data);
+ sha3.finalize();
});
}
|
代码块 |
---|
Intel(R) Xeon(R) CPU E5-2666 v3 @ 2.90GHz 7G Memory |
我在跳板机上测试结论
代码块 |
---|
rustup run nightly cargo bench
running 4 tests
test rust_crypto_sha3_256_input_32_bytes ... bench: 599 ns/iter (+/- 12) = 53 MB/s
test rust_crypto_sha3_256_input_4096_bytes ... bench: 17,665 ns/iter (+/- 96) = 231 MB/s
test tiny_keccak_sha3_256_input_32_bytes ... bench: 595 ns/iter (+/- 5) = 53 MB/s
test tiny_keccak_sha3_256_input_4096_bytes ... bench: 17,737 ns/iter (+/- 158) = 230 MB/s
|
在macOs上
代码块 |
---|
running 4 tests test rust_crypto_sha3_256_input_32_bytes ... bench: 441 ns/iter (+/- 47) = 72 MB/s test rust_crypto_sha3_256_input_4096_bytes ... bench: 12,875 ns/iter (+/- 775) = 318 MB/s test tiny_keccak_sha3_256_input_32_bytes ... bench: 452 ns/iter (+/- 23) = 70 MB/s test tiny_keccak_sha3_256_input_4096_bytes ... bench: 13,073 ns/iter (+/- 880) = 313 MB/s |
...