Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 17 additions & 23 deletions tests/benchmark/compute/instruction/test_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,40 +98,34 @@ def test_memory_access(
)


@pytest.mark.repricing(fixed_src_dst=True)
@pytest.mark.repricing
@pytest.mark.parametrize(
"mem_size",
[0, 32, 256, 1024, 10 * 1024, 1024 * 1024],
)
@pytest.mark.parametrize("copy_size", [0, 32, 256, 1024])
@pytest.mark.parametrize(
"fixed_src_dst",
"copy_size",
[
True,
False,
# Copy nothing: only the base cost, without the per-word cost.
0,
# One full word: the largest copy at the one-word price.
32,
# A long copy, to check the per-word cost. The longer the copy,
# the more gas per second it runs, so this is not the worst case.
1024,
],
)
def test_mcopy(
benchmark_test: BenchmarkTestFiller,
mem_size: int,
copy_size: int,
fixed_src_dst: bool,
) -> None:
"""Benchmark MCOPY instruction."""
src_dst = 0 if fixed_src_dst else Op.MOD(Op.GAS, 7)
attack_block = Op.MCOPY(src_dst, src_dst, copy_size)

mem_touch = (
Op.MSTORE8(0, Op.GAS)
+ Op.MSTORE8(mem_size // 2, Op.GAS)
+ Op.MSTORE8(mem_size - 1, Op.GAS)
if mem_size > 0
else Bytecode()
)
"""
Benchmark MCOPY instruction.

The destination is one byte above the source, so the ranges overlap
and both are unaligned. Copying a range onto itself would be cheaper.
"""
src = 1
benchmark_test(
target_opcode=Op.MCOPY,
code_generator=JumpLoopGenerator(
attack_block=attack_block, cleanup=mem_touch
attack_block=Op.MCOPY(src + 1, src, copy_size)
),
)

Expand Down
Loading