rust: Add benchmark comparing to software implementation

This commit is contained in:
Wladimir J. van der Laan 2020-04-29 16:51:03 +00:00
parent b695136eaa
commit 9d9f67692b
2 changed files with 18 additions and 0 deletions

View File

@ -10,3 +10,4 @@ k210-shared = { path = "../k210-shared" }
riscv = "0.5" riscv = "0.5"
riscv-rt = "0.6" riscv-rt = "0.6"
hex-literal = "0.2" hex-literal = "0.2"
sha2 = { version = "0.8", default-features = false }

View File

@ -16,6 +16,7 @@ use k210_shared::soc::sha256::SHA256Ctx;
use k210_shared::timing::clock; use k210_shared::timing::clock;
use riscv::asm; use riscv::asm;
use riscv_rt::entry; use riscv_rt::entry;
use sha2::{Sha256, Digest};
struct AESTestVec { struct AESTestVec {
cipher_mode: cipher_mode, cipher_mode: cipher_mode,
@ -567,6 +568,22 @@ fn main() -> ! {
} }
write!(stdout, " ({} kB/s)", (size as u64) * 1_000 / (time_end - time_start)).unwrap(); write!(stdout, " ({} kB/s)", (size as u64) * 1_000 / (time_end - time_start)).unwrap();
writeln!(stdout).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 { loop {