ExWeb3 / ex_keccak

Elixir library for computing Keccak SHA3-256 hashes using a NIF built tiny-keccak Rust crate.
Apache License 2.0
25 stars 20 forks source link

Add performance tests #3

Closed ayrat555 closed 3 years ago

ayrat555 commented 3 years ago

I added performance tests to make sure the Nif won't fail on load.

Sidenote: I just benchmarked ex_keccak Rust Nif and keccakf1600 C Nif. Unfortunately, ex_keccak is slower both in sequential and parallel benchmarks. I compiled ex_keccak in release mode.

it's ~2,06 times slower in the sequential bench. and ~4 times slower in the parallel bench sequential:

Benchmarking ex_keccak...
Benchmarking keccakf1600...

Name                  ips        average  deviation         median         99th %
keccakf1600      719.32 K        1.39 μs  ±1753.16%        1.24 μs        2.23 μs
ex_keccak        349.23 K        2.86 μs   ±971.32%        2.42 μs        7.23 μs

Comparison: 
keccakf1600      719.32 K
ex_keccak        349.23 K - 2.06x slower +1.47 μs

Memory usage statistics:

Name           Memory usage
keccakf1600            48 B
ex_keccak             120 B - 2.50x memory usage +72 B

Parallel (6 processes):

Benchmarking ex_keccak...
Benchmarking keccakf1600...

Name                  ips        average  deviation         median         99th %
keccakf1600      462.56 K        2.16 μs   ±743.60%        2.58 μs        2.88 μs
ex_keccak        113.86 K        8.78 μs   ±823.86%        4.92 μs       38.62 μs

Comparison: 
keccakf1600      462.56 K
ex_keccak        113.86 K - 4.06x slower +6.62 μs

Memory usage statistics:

Name           Memory usage
keccakf1600            48 B
ex_keccak             120 B - 2.50x memory usage +72 B
tzumby commented 3 years ago

Thanks! I suspect it has something to do with how we allocate the mutable binary for returning the data in Rust.