computation time test

This commit is contained in:
Aravinth Manivannan 2021-04-02 10:17:52 +05:30
parent df727889c6
commit f97858cd63
Signed by: realaravinth
GPG key ID: AD9F0F08E855ED88
3 changed files with 25 additions and 3 deletions

BIN
main

Binary file not shown.

View file

@ -1,3 +0,0 @@
pub fn main() {
println!("{}", u128::MAX / 1000);
}

View file

@ -213,6 +213,31 @@ mod test {
assert!(!config.is_valid_proof(&pw2, &phrase));
}
fn check_time(prev: u128, current: u128) -> bool {
if prev < current {
true
} else {
false
}
}
#[test]
fn computation_time_test() {
use std::time::Instant;
const DIFFICULTY: u32 = 50000;
let target = "testing";
let config = get_config();
let mut current = Instant::now();
config.prove_work(&target, DIFFICULTY).unwrap();
let prev = current.elapsed().as_nanos();
current = Instant::now();
config.prove_work(&target, DIFFICULTY * 10).unwrap();
let tmp = current.elapsed().as_nanos();
assert!(check_time(prev, tmp));
}
#[test]
fn serialization_test() {
let target: u8 = 1;