Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move benchmark contracts to era_vm #218

Merged
merged 14 commits into from
Aug 29, 2024
Merged

Move benchmark contracts to era_vm #218

merged 14 commits into from
Aug 29, 2024

Conversation

JulianVentura
Copy link
Contributor

This PR moves custom made benchmark contracts sources from zksync-era to era_vm, so its easier to modify them.
It also adds a new benchmark result processing script made in python, which allows us to easily aggregate all benchmark execution times.

Copy link

github-actions bot commented Aug 28, 2024

Ergs comparison results:

╔═╡ Size (-%) ╞════════════════╡ All M3B3 ╞═╗
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                                 NaN ║
╠═╡ Cycles (-%) ╞══════════════╡ All M3B3 ╞═╣
║ Mean                              100.000 ║
║ Best                              100.000 ║
║ Worst                               0.000 ║
║ Total                             100.000 ║
╠═╡ Ergs (-%) ╞════════════════╡ All M3B3 ╞═╣
║ Mean                              100.000 ║
║ Best                              100.000 ║
║ Worst                               0.000 ║
║ Total                             100.000 ║
╚═══════════════════════════════════════════╝

╔═╡ Size (-%) ╞════════════════╡ All MzB3 ╞═╗
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                                 NaN ║
╠═╡ Cycles (-%) ╞══════════════╡ All MzB3 ╞═╣
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                                 NaN ║
╠═╡ Ergs (-%) ╞════════════════╡ All MzB3 ╞═╣
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                                 NaN ║
╚═══════════════════════════════════════════╝

╔═╡ Size (-%) ╞═════╡ EVMInterpreter M3B3 ╞═╗
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                                 NaN ║
╠═╡ Cycles (-%) ╞═══╡ EVMInterpreter M3B3 ╞═╣
║ Mean                              100.000 ║
║ Best                              100.000 ║
║ Worst                               0.000 ║
║ Total                             100.000 ║
╠═╡ Ergs (-%) ╞═════╡ EVMInterpreter M3B3 ╞═╣
║ Mean                              100.000 ║
║ Best                              100.000 ║
║ Worst                               0.000 ║
║ Total                             100.000 ║
╠═╡ Ergs/gas ╞══════╡ EVMInterpreter M3B3 ╞═╣
║ ADD                                 0.000 ║
║ MUL                                 0.000 ║
║ SUB                                 0.000 ║
║ DIV                                 0.000 ║
║ SDIV                                0.000 ║
║ MOD                                 0.000 ║
║ SMOD                                0.000 ║
║ ADDMOD                              0.000 ║
║ MULMOD                              0.000 ║
║ EXP                                 0.000 ║
║ SIGNEXTEND                          0.000 ║
║ LT                                  0.000 ║
║ GT                                  0.000 ║
║ SLT                                 0.000 ║
║ SGT                                 0.000 ║
║ EQ                                  0.000 ║
║ ISZERO                              0.000 ║
║ AND                                 0.000 ║
║ OR                                  0.000 ║
║ XOR                                 0.000 ║
║ NOT                                 0.000 ║
║ BYTE                                0.000 ║
║ SHL                                 0.000 ║
║ SHR                                 0.000 ║
║ SAR                                 0.000 ║
║ SGT                                 0.000 ║
║ SHA3                                0.000 ║
║ ADDRESS                             0.000 ║
║ BALANCE                             0.000 ║
║ ORIGIN                              0.000 ║
║ CALLER                              0.000 ║
║ CALLVALUE                           0.000 ║
║ CALLDATALOAD                        0.000 ║
║ CALLDATASIZE                        0.000 ║
║ CALLDATACOPY                        0.000 ║
║ CODESIZE                            0.000 ║
║ CODECOPY                            0.000 ║
║ GASPRICE                            0.000 ║
║ EXTCODESIZE                         0.000 ║
║ EXTCODECOPY                         0.000 ║
║ RETURNDATASIZE                      0.000 ║
║ RETURNDATACOPY                      0.000 ║
║ EXTCODEHASH                         0.000 ║
║ BLOCKHASH                           0.000 ║
║ COINBASE                            0.000 ║
║ TIMESTAMP                           0.000 ║
║ NUMBER                              0.000 ║
║ PREVRANDAO                          0.000 ║
║ GASLIMIT                            0.000 ║
║ CHAINID                             0.000 ║
║ SELFBALANCE                         0.000 ║
║ BASEFEE                             0.000 ║
║ POP                                 0.000 ║
║ MLOAD                               0.000 ║
║ MSTORE                              0.000 ║
║ MSTORE8                             0.000 ║
║ SLOAD                               0.000 ║
║ SSTORE                              0.000 ║
║ JUMP                                0.000 ║
║ JUMPI                               0.000 ║
║ PC                                  0.000 ║
║ MSIZE                               0.000 ║
║ GAS                                 0.000 ║
║ JUMPDEST                            0.000 ║
║ PUSH0                               0.000 ║
║ PUSH1                               0.000 ║
║ PUSH2                               0.000 ║
║ PUSH4                               0.000 ║
║ PUSH5                               0.000 ║
║ PUSH6                               0.000 ║
║ PUSH7                               0.000 ║
║ PUSH8                               0.000 ║
║ PUSH9                               0.000 ║
║ PUSH10                              0.000 ║
║ PUSH11                              0.000 ║
║ PUSH12                              0.000 ║
║ PUSH13                              0.000 ║
║ PUSH14                              0.000 ║
║ PUSH15                              0.000 ║
║ PUSH16                              0.000 ║
║ PUSH17                              0.000 ║
║ PUSH18                              0.000 ║
║ PUSH19                              0.000 ║
║ PUSH20                              0.000 ║
║ PUSH21                              0.000 ║
║ PUSH22                              0.000 ║
║ PUSH23                              0.000 ║
║ PUSH24                              0.000 ║
║ PUSH25                              0.000 ║
║ PUSH26                              0.000 ║
║ PUSH27                              0.000 ║
║ PUSH28                              0.000 ║
║ PUSH29                              0.000 ║
║ PUSH30                              0.000 ║
║ PUSH31                              0.000 ║
║ PUSH32                              0.000 ║
║ DUP1                                0.000 ║
║ DUP2                                0.000 ║
║ DUP3                                0.000 ║
║ DUP4                                0.000 ║
║ DUP5                                0.000 ║
║ DUP6                                0.000 ║
║ DUP7                                0.000 ║
║ DUP8                                0.000 ║
║ DUP9                                0.000 ║
║ DUP10                               0.000 ║
║ DUP11                               0.000 ║
║ DUP12                               0.000 ║
║ DUP13                               0.000 ║
║ DUP14                               0.000 ║
║ DUP15                               0.000 ║
║ DUP16                               0.000 ║
║ SWAP1                               0.000 ║
║ SWAP2                               0.000 ║
║ SWAP3                               0.000 ║
║ SWAP4                               0.000 ║
║ SWAP5                               0.000 ║
║ SWAP6                               0.000 ║
║ SWAP7                               0.000 ║
║ SWAP8                               0.000 ║
║ SWAP9                               0.000 ║
║ SWAP10                              0.000 ║
║ SWAP11                              0.000 ║
║ SWAP12                              0.000 ║
║ SWAP13                              0.000 ║
║ SWAP14                              0.000 ║
║ SWAP15                              0.000 ║
║ SWAP16                              0.000 ║
║ CALL                                0.000 ║
║ STATICCALL                          0.000 ║
║ DELEGATECALL                        0.000 ║
║ CREATE                              0.000 ║
║ CREATE2                             0.000 ║
║ RETURN                              0.000 ║
║ REVERT                              0.000 ║
╠═╡ Ergs/gas (-%) ╞═╡ EVMInterpreter M3B3 ╞═╣
║ ADD                               100.000 ║
║ MUL                               100.000 ║
║ SUB                               100.000 ║
║ DIV                               100.000 ║
║ SDIV                              100.000 ║
║ MOD                               100.000 ║
║ SMOD                              100.000 ║
║ ADDMOD                            100.000 ║
║ MULMOD                            100.000 ║
║ EXP                               100.000 ║
║ SIGNEXTEND                        100.000 ║
║ LT                                100.000 ║
║ GT                                100.000 ║
║ SLT                               100.000 ║
║ SGT                               100.000 ║
║ EQ                                100.000 ║
║ ISZERO                            100.000 ║
║ AND                               100.000 ║
║ OR                                100.000 ║
║ XOR                               100.000 ║
║ NOT                               100.000 ║
║ BYTE                              100.000 ║
║ SHL                               100.000 ║
║ SHR                               100.000 ║
║ SAR                               100.000 ║
║ SGT                               100.000 ║
║ SHA3                              100.000 ║
║ ADDRESS                           100.000 ║
║ BALANCE                           100.000 ║
║ ORIGIN                            100.000 ║
║ CALLER                            100.000 ║
║ CALLVALUE                         100.000 ║
║ CALLDATALOAD                      100.000 ║
║ CALLDATASIZE                      100.000 ║
║ CALLDATACOPY                      100.000 ║
║ CODESIZE                          100.000 ║
║ CODECOPY                          100.000 ║
║ GASPRICE                          100.000 ║
║ EXTCODESIZE                       100.000 ║
║ EXTCODECOPY                       100.000 ║
║ RETURNDATASIZE                    100.000 ║
║ RETURNDATACOPY                    100.000 ║
║ EXTCODEHASH                       100.000 ║
║ BLOCKHASH                         100.000 ║
║ COINBASE                          100.000 ║
║ TIMESTAMP                         100.000 ║
║ NUMBER                            100.000 ║
║ PREVRANDAO                        100.000 ║
║ GASLIMIT                          100.000 ║
║ CHAINID                           100.000 ║
║ SELFBALANCE                       100.000 ║
║ BASEFEE                           100.000 ║
║ POP                               100.000 ║
║ MLOAD                             100.000 ║
║ MSTORE                            100.000 ║
║ MSTORE8                           100.000 ║
║ SLOAD                             100.000 ║
║ SSTORE                            100.000 ║
║ JUMP                              100.000 ║
║ JUMPI                             100.000 ║
║ PC                                100.000 ║
║ MSIZE                             100.000 ║
║ GAS                               100.000 ║
║ JUMPDEST                          100.000 ║
║ PUSH0                             100.000 ║
║ PUSH1                             100.000 ║
║ PUSH2                             100.000 ║
║ PUSH4                             100.000 ║
║ PUSH5                             100.000 ║
║ PUSH6                             100.000 ║
║ PUSH7                             100.000 ║
║ PUSH8                             100.000 ║
║ PUSH9                             100.000 ║
║ PUSH10                            100.000 ║
║ PUSH11                            100.000 ║
║ PUSH12                            100.000 ║
║ PUSH13                            100.000 ║
║ PUSH14                            100.000 ║
║ PUSH15                            100.000 ║
║ PUSH16                            100.000 ║
║ PUSH17                            100.000 ║
║ PUSH18                            100.000 ║
║ PUSH19                            100.000 ║
║ PUSH20                            100.000 ║
║ PUSH21                            100.000 ║
║ PUSH22                            100.000 ║
║ PUSH23                            100.000 ║
║ PUSH24                            100.000 ║
║ PUSH25                            100.000 ║
║ PUSH26                            100.000 ║
║ PUSH27                            100.000 ║
║ PUSH28                            100.000 ║
║ PUSH29                            100.000 ║
║ PUSH30                            100.000 ║
║ PUSH31                            100.000 ║
║ PUSH32                            100.000 ║
║ DUP1                              100.000 ║
║ DUP2                              100.000 ║
║ DUP3                              100.000 ║
║ DUP4                              100.000 ║
║ DUP5                              100.000 ║
║ DUP6                              100.000 ║
║ DUP7                              100.000 ║
║ DUP8                              100.000 ║
║ DUP9                              100.000 ║
║ DUP10                             100.000 ║
║ DUP11                             100.000 ║
║ DUP12                             100.000 ║
║ DUP13                             100.000 ║
║ DUP14                             100.000 ║
║ DUP15                             100.000 ║
║ DUP16                             100.000 ║
║ SWAP1                             100.000 ║
║ SWAP2                             100.000 ║
║ SWAP3                             100.000 ║
║ SWAP4                             100.000 ║
║ SWAP5                             100.000 ║
║ SWAP6                             100.000 ║
║ SWAP7                             100.000 ║
║ SWAP8                             100.000 ║
║ SWAP9                             100.000 ║
║ SWAP10                            100.000 ║
║ SWAP11                            100.000 ║
║ SWAP12                            100.000 ║
║ SWAP13                            100.000 ║
║ SWAP14                            100.000 ║
║ SWAP15                            100.000 ║
║ SWAP16                            100.000 ║
║ CALL                              100.000 ║
║ STATICCALL                        100.000 ║
║ DELEGATECALL                      100.000 ║
║ CREATE                            100.000 ║
║ CREATE2                           100.000 ║
║ RETURN                            100.000 ║
║ REVERT                            100.000 ║
╚═══════════════════════════════════════════╝

@fkrause98 fkrause98 marked this pull request as ready for review August 29, 2024 15:28
@@ -84,6 +84,9 @@ bench-setup: submodules build_bench_contracts $(ZKSYNC_BENCH_TEST_DATA) $(ZKSYNC
bench:
cd $(ZKSYNC_ROOT) && cargo bench --bench criterion "$(lambda|fast_vm|legacy)/(fibonacci|send)"

check-flamegraph:
cd $(ZKSYNC_ROOT) && CARGO_PROFILE_BENCH_DEBUG=2 cargo flamegraph --root --bench criterion -- --bench --profile-time 5 "$lambda/fibonacci_rec^"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the $lambda is converted to ambda for some reason. What does $l do here? Is the $ even necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it is not necessary actually. I had been using it without any problems though, so I think it works ok.

Comment on lines +14 to +30
def parse_benchmark_file(file_path):
machines = {}
pattern = r'(\w+)/\w+\s+time:\s+\[\d+(?:\.\d+)?\s(\w+)\s(\d+(?:\.\d+)?)\s(\w+)\s\d+(?:\.\d+)?\s(\w+)\]'

with open(file_path, 'r') as file:
content = file.read()
# Clean the file content
cleaned_content = re.sub(r'\n(\s+)time:', ' time:', content)
for line in cleaned_content.split('\n'):
match = re.match(pattern, line)
if match:
machine, lower_unit, mid_time, mid_unit, upper_unit = match.groups()
# Convert mid_time to milliseconds
mid_time_ms = convert_to_ms(float(mid_time), mid_unit)
machines[machine] = machines.get(machine, 0) + mid_time_ms

return machines
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

criterion is capable of emitting JSON IIRC. Maybe that could save you parsing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know that, it might be useful to improve the script. Thanks!

@Oppen
Copy link
Member

Oppen commented Aug 29, 2024

Just to make sure, we should check the generated assembly for the contracts to confirm they do what we think they do.

@JulianVentura
Copy link
Contributor Author

LGTM

@fkrause98 fkrause98 merged commit 6b5efb9 into main Aug 29, 2024
188 checks passed
@fkrause98 fkrause98 deleted the fix_contracts branch August 29, 2024 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants