add a profiling test

This commit is contained in:
chirag-parmar 2024-11-22 00:14:04 +05:30
parent 88e4be4dc4
commit 24a871f85d
2 changed files with 39 additions and 1 deletions

View File

@ -3,4 +3,5 @@ import
./test_json_suite,
./test_empty_string,
./test_object_serialization,
./test_optional_fields
./test_optional_fields,
./test_rlp_profiler

View File

@ -0,0 +1,37 @@
{.used.}
import
../../eth/[rlp, common],
unittest2,
times,
os,
strutils
template benchmark(benchmarkName: string, code: untyped) =
block:
let t0 = epochTime()
code
let elapsed = epochTime() - t0
let elapsedStr = elapsed.formatFloat(format = ffDecimal, precision = 9)
echo "CPU Time [", benchmarkName, "] ", elapsedStr, "s"
const
accesses = @[AccessPair(
address: address"0x0000000000000000000000000000000000000001",
storageKeys: @[default(Bytes32)]
)]
let my_tx = Transaction(
txType: TxEip1559,
chainId: 1.ChainId,
nonce: 0.AccountNonce,
gasLimit: 123457.GasInt,
maxPriorityFeePerGas: 42.GasInt,
maxFeePerGas: 10.GasInt,
accessList: accesses
)
suite "test running time of rlp serialization":
test "transaction serialization":
benchmark "Transaction":
let my_bytes = rlp.encode(my_tx)