|
6 | 6 |
|
7 | 7 | import faster_hexbytes
|
8 | 8 | from benchmarks.params import (
|
9 |
| - CONSTRUCTOR_VALS, CONSTRUCTOR_IDS, |
10 |
| - BYTES_VALS, BYTES_IDS, |
11 |
| - SLICES, SLICE_IDS, |
| 9 | + CONSTRUCTOR_VALS, |
| 10 | + CONSTRUCTOR_IDS, |
| 11 | + BYTES_VALS, |
| 12 | + BYTES_IDS, |
| 13 | + SLICES, |
| 14 | + SLICE_IDS, |
12 | 15 | )
|
13 | 16 |
|
| 17 | + |
14 | 18 | def run_100(func: Callable[..., Any], *args: Any) -> None:
|
15 | 19 | for i in range(100):
|
16 | 20 | func(*args)
|
17 | 21 |
|
| 22 | + |
18 | 23 | @pytest.mark.benchmark(group="HexBytes.__new__")
|
19 | 24 | @pytest.mark.parametrize("val", CONSTRUCTOR_VALS, ids=CONSTRUCTOR_IDS)
|
20 | 25 | def test_hexbytes_new(benchmark: BenchmarkFixture, val: Any) -> None:
|
21 | 26 | benchmark(run_100, hexbytes.HexBytes, val)
|
22 | 27 |
|
| 28 | + |
23 | 29 | @pytest.mark.benchmark(group="HexBytes.__new__")
|
24 | 30 | @pytest.mark.parametrize("val", CONSTRUCTOR_VALS, ids=CONSTRUCTOR_IDS)
|
25 | 31 | def test_faster_hexbytes_new(benchmark: BenchmarkFixture, val: Any) -> None:
|
26 | 32 | benchmark(run_100, faster_hexbytes.HexBytes, val)
|
27 | 33 |
|
| 34 | + |
28 | 35 | @pytest.mark.benchmark(group="HexBytes.__getitem__ (index)")
|
29 | 36 | @pytest.mark.parametrize("val", BYTES_VALS, ids=BYTES_IDS)
|
30 | 37 | @pytest.mark.parametrize("idx", [0, 1, 2, 3, 4, 5, -1])
|
31 |
| -def test_hexbytes_getitem_index(benchmark: BenchmarkFixture, val: bytes, idx: int) -> None: |
| 38 | +def test_hexbytes_getitem_index( |
| 39 | + benchmark: BenchmarkFixture, val: bytes, idx: int |
| 40 | +) -> None: |
32 | 41 | obj = hexbytes.HexBytes(val)
|
33 | 42 | if len(val) > abs(idx):
|
34 | 43 | benchmark(run_100, lambda: obj[idx])
|
35 | 44 |
|
| 45 | + |
36 | 46 | @pytest.mark.benchmark(group="HexBytes.__getitem__ (index)")
|
37 | 47 | @pytest.mark.parametrize("val", BYTES_VALS, ids=BYTES_IDS)
|
38 | 48 | @pytest.mark.parametrize("idx", [0, 1, 2, 3, 4, 5, -1])
|
39 |
| -def test_faster_hexbytes_getitem_index(benchmark: BenchmarkFixture, val: bytes, idx: int) -> None: |
| 49 | +def test_faster_hexbytes_getitem_index( |
| 50 | + benchmark: BenchmarkFixture, val: bytes, idx: int |
| 51 | +) -> None: |
40 | 52 | obj = faster_hexbytes.HexBytes(val)
|
41 | 53 | if len(val) > abs(idx):
|
42 | 54 | benchmark(run_100, lambda: obj[idx])
|
43 | 55 |
|
| 56 | + |
44 | 57 | @pytest.mark.benchmark(group="HexBytes.__getitem__ (slice)")
|
45 | 58 | @pytest.mark.parametrize("val", BYTES_VALS, ids=BYTES_IDS)
|
46 | 59 | @pytest.mark.parametrize("slice_", SLICES, ids=SLICE_IDS)
|
47 |
| -def test_hexbytes_getitem_slice(benchmark: BenchmarkFixture, val: bytes, slice_: slice) -> None: |
| 60 | +def test_hexbytes_getitem_slice( |
| 61 | + benchmark: BenchmarkFixture, val: bytes, slice_: slice |
| 62 | +) -> None: |
48 | 63 | obj = hexbytes.HexBytes(val)
|
49 | 64 | benchmark(run_100, lambda: obj[slice_])
|
50 | 65 |
|
| 66 | + |
51 | 67 | @pytest.mark.benchmark(group="HexBytes.__getitem__ (slice)")
|
52 | 68 | @pytest.mark.parametrize("val", BYTES_VALS, ids=BYTES_IDS)
|
53 | 69 | @pytest.mark.parametrize("slice_", SLICES, ids=SLICE_IDS)
|
54 |
| -def test_faster_hexbytes_getitem_slice(benchmark: BenchmarkFixture, val: bytes, slice_: slice) -> None: |
| 70 | +def test_faster_hexbytes_getitem_slice( |
| 71 | + benchmark: BenchmarkFixture, val: bytes, slice_: slice |
| 72 | +) -> None: |
55 | 73 | obj = faster_hexbytes.HexBytes(val)
|
56 | 74 | benchmark(run_100, lambda: obj[slice_])
|
57 | 75 |
|
| 76 | + |
58 | 77 | @pytest.mark.benchmark(group="HexBytes.__repr__")
|
59 | 78 | @pytest.mark.parametrize("val", BYTES_VALS, ids=BYTES_IDS)
|
60 | 79 | def test_hexbytes_repr(benchmark: BenchmarkFixture, val: bytes) -> None:
|
61 | 80 | obj = hexbytes.HexBytes(val)
|
62 | 81 | benchmark(run_100, obj.__repr__)
|
63 | 82 |
|
| 83 | + |
64 | 84 | @pytest.mark.benchmark(group="HexBytes.__repr__")
|
65 | 85 | @pytest.mark.parametrize("val", BYTES_VALS, ids=BYTES_IDS)
|
66 | 86 | def test_faster_hexbytes_repr(benchmark: BenchmarkFixture, val: bytes) -> None:
|
67 | 87 | obj = faster_hexbytes.HexBytes(val)
|
68 | 88 | benchmark(run_100, obj.__repr__)
|
69 | 89 |
|
| 90 | + |
70 | 91 | @pytest.mark.benchmark(group="HexBytes.to_0x_hex")
|
71 | 92 | @pytest.mark.parametrize("val", BYTES_VALS, ids=BYTES_IDS)
|
72 | 93 | def test_hexbytes_to_0x_hex(benchmark: BenchmarkFixture, val: bytes) -> None:
|
73 | 94 | obj = hexbytes.HexBytes(val)
|
74 | 95 | benchmark(run_100, obj.to_0x_hex)
|
75 | 96 |
|
| 97 | + |
76 | 98 | @pytest.mark.benchmark(group="HexBytes.to_0x_hex")
|
77 | 99 | @pytest.mark.parametrize("val", BYTES_VALS, ids=BYTES_IDS)
|
78 | 100 | def test_faster_hexbytes_to_0x_hex(benchmark: BenchmarkFixture, val: bytes) -> None:
|
|
0 commit comments