Skip to content

Commit

Permalink
Benchmark argon2 execution
Browse files Browse the repository at this point in the history
  • Loading branch information
webmaster128 committed Sep 29, 2021
1 parent 3523a1e commit 145fd63
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ workflows:
- load-wasm-speed
- cache-analyze
- fix-benches
- benchmark_argon2
deploy:
jobs:
- build_and_upload_devcontracts:
Expand Down
30 changes: 29 additions & 1 deletion packages/vm/benches/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fn bench_instance(c: &mut Criterion) {
});
});

group.bench_function("execute execute", |b| {
group.bench_function("execute execute (release)", |b| {
let backend = mock_backend(&[]);
let much_gas: InstanceOptions = InstanceOptions {
gas_limit: 500_000_000_000,
Expand All @@ -77,6 +77,34 @@ fn bench_instance(c: &mut Criterion) {
});
});

group.bench_function("execute execute (argon2)", |b| {
let backend = mock_backend(&[]);
let much_gas: InstanceOptions = InstanceOptions {
gas_limit: 500_000_000_000,
..DEFAULT_INSTANCE_OPTIONS
};
let mut instance =
Instance::from_code(CONTRACT, backend, much_gas, Some(DEFAULT_MEMORY_LIMIT)).unwrap();

let info = mock_info("creator", &coins(1000, "earth"));
let msg = br#"{"verifier": "verifies", "beneficiary": "benefits"}"#;
let contract_result =
call_instantiate::<_, _, _, Empty>(&mut instance, &mock_env(), &info, msg).unwrap();
assert!(contract_result.into_result().is_ok());

let mut gas_used = 0;
b.iter(|| {
let gas_before = instance.get_gas_left();
let info = mock_info("hasher", &[]);
let msg = br#"{"argon2":{"mem_cost":512,"time_cost":7}}"#;
let contract_result =
call_execute::<_, _, _, Empty>(&mut instance, &mock_env(), &info, msg).unwrap();
assert!(contract_result.into_result().is_ok());
gas_used = gas_before - instance.get_gas_left();
});
println!("Gas used: {}", gas_used);
});

group.finish();
}

Expand Down

0 comments on commit 145fd63

Please sign in to comment.