mirror of
https://github.com/laanwj/k210-sdk-stuff.git
synced 2024-11-21 17:06:19 +04:00
rust: Add benchmark comparing to software implementation
This commit is contained in:
parent
b695136eaa
commit
9d9f67692b
@ -10,3 +10,4 @@ k210-shared = { path = "../k210-shared" }
|
||||
riscv = "0.5"
|
||||
riscv-rt = "0.6"
|
||||
hex-literal = "0.2"
|
||||
sha2 = { version = "0.8", default-features = false }
|
||||
|
@ -16,6 +16,7 @@ use k210_shared::soc::sha256::SHA256Ctx;
|
||||
use k210_shared::timing::clock;
|
||||
use riscv::asm;
|
||||
use riscv_rt::entry;
|
||||
use sha2::{Sha256, Digest};
|
||||
|
||||
struct AESTestVec {
|
||||
cipher_mode: cipher_mode,
|
||||
@ -567,6 +568,22 @@ fn main() -> ! {
|
||||
}
|
||||
write!(stdout, " ({} kB/s)", (size as u64) * 1_000 / (time_end - time_start)).unwrap();
|
||||
writeln!(stdout).unwrap();
|
||||
|
||||
// Software
|
||||
write!(stdout, "SHA256 sw ({} bytes): ", size).unwrap();
|
||||
let time_start = clock();
|
||||
let mut hasher = Sha256::new();
|
||||
for _ in 0..65_535 {
|
||||
hasher.input(&s[..]);
|
||||
}
|
||||
let time_end = clock();
|
||||
if hasher.result()[..] == expected {
|
||||
write!(stdout, "MATCH").unwrap();
|
||||
} else {
|
||||
write!(stdout, "MISMATCH").unwrap();
|
||||
}
|
||||
write!(stdout, " ({} kB/s)", (size as u64) * 1_000 / (time_end - time_start)).unwrap();
|
||||
writeln!(stdout).unwrap();
|
||||
}
|
||||
|
||||
loop {
|
||||
|
Loading…
Reference in New Issue
Block a user