forked from safe-global/safe-transaction-service
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import os | ||
|
||
import sha3 | ||
from Crypto.Hash import keccak as crypto_keccak | ||
from eth_hash.auto import keccak as eth_hash_keccak | ||
from web3 import Web3 | ||
|
||
|
||
def eth_hash_benchmark(): | ||
return eth_hash_keccak(os.urandom(32)).hex() | ||
|
||
|
||
def web3_benchmark(): | ||
return Web3.keccak(os.urandom(32)).hex() | ||
|
||
|
||
def cryptodome_benchmark(): | ||
k = crypto_keccak.new(data=os.urandom(32), digest_bits=256) | ||
return k.hexdigest() | ||
|
||
|
||
def pysha3_benchmark(): | ||
return sha3.keccak_256(os.urandom(32)).hexdigest() | ||
|
||
|
||
if __name__ == "__main__": | ||
import timeit | ||
|
||
print( | ||
"eth_hash", | ||
timeit.timeit( | ||
"eth_hash_benchmark()", | ||
setup="from __main__ import eth_hash_benchmark", | ||
number=500000, | ||
globals=globals(), | ||
), | ||
) | ||
print( | ||
"web3", | ||
timeit.timeit( | ||
"web3_benchmark()", | ||
setup="from __main__ import web3_benchmark", | ||
number=500000, | ||
globals=globals(), | ||
), | ||
) | ||
print( | ||
"cryptodome", | ||
timeit.timeit( | ||
"cryptodome_benchmark()", | ||
setup="from __main__ import cryptodome_benchmark", | ||
number=500000, | ||
globals=globals(), | ||
), | ||
) | ||
print( | ||
"pysha3", | ||
timeit.timeit( | ||
"pysha3_benchmark()", | ||
setup="from __main__ import pysha3_benchmark", | ||
number=500000, | ||
globals=globals(), | ||
), | ||
) |