Skip to content

Commit

Permalink
Add Pedersen hash benchmark (#950)
Browse files Browse the repository at this point in the history
  • Loading branch information
Oppen authored Apr 10, 2023
1 parent 725c17e commit c93b3fc
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions bench/criterion_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const BENCH_NAMES: &[&str] = &[
"operations_with_data_structures_benchmarks",
"uint256_integration_benchmark",
"set_integration_benchmark",
"pedersen",
];
const BENCH_PATH: &str = "cairo_programs/benchmarks/";

Expand Down
2 changes: 2 additions & 0 deletions bench/iai_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ iai_bench_expand_prog! {math_cmp_and_pow_integration_benchmark}
iai_bench_expand_prog! {operations_with_data_structures_benchmarks}
iai_bench_expand_prog! {uint256_integration_benchmark}
iai_bench_expand_prog! {set_integration_benchmark}
iai_bench_expand_prog! {pedersen}

main!(
math_integration_benchmark,
Expand All @@ -132,4 +133,5 @@ main!(
operations_with_data_structures_benchmarks,
uint256_integration_benchmark,
set_integration_benchmark,
pedersen,
);
45 changes: 45 additions & 0 deletions cairo_programs/benchmarks/pedersen.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
%builtins pedersen

from starkware.cairo.common.cairo_builtins import HashBuiltin
from starkware.cairo.common.hash import hash2

func get_hash(hash_ptr: HashBuiltin*, num_a: felt, num_b: felt) -> (
hash_ptr: HashBuiltin*, r: felt
) {
with hash_ptr {
let (result) = hash2(num_a, num_b);
}
return (hash_ptr=hash_ptr, r=result);
}

func builtins_wrapper{
pedersen_ptr: HashBuiltin*,
}(num_a: felt, num_b: felt) {
let (pedersen_ptr, result: felt) = get_hash(pedersen_ptr, num_a, num_b);

return ();
}

func builtins_wrapper_iter{
pedersen_ptr: HashBuiltin*,
}(num_a: felt, num_b: felt, n_iterations: felt) {
builtins_wrapper(num_a, num_b);
if (n_iterations != 0) {
builtins_wrapper_iter(num_a, num_b, n_iterations - 1);
tempvar pedersen_ptr = pedersen_ptr;
} else {
tempvar pedersen_ptr = pedersen_ptr;
}

return ();
}

func main{
pedersen_ptr: HashBuiltin*,
}() {
let num_a = 123568;
let num_b = 5673940;
builtins_wrapper_iter(num_a, num_b, 50000);

return ();
}

0 comments on commit c93b3fc

Please sign in to comment.