cchecksum 0.4.0__cp311-cp311-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- benchmarks/__init__.py +0 -0
- benchmarks/data.py +70 -0
- benchmarks/test_checksum_benchmarks.py +23 -0
- cchecksum/__init__.py +15 -0
- cchecksum/_checksum.c +32263 -0
- cchecksum/_checksum.cpython-311-i386-linux-gnu.so +0 -0
- cchecksum/_checksum.pyi +72 -0
- cchecksum/_checksum.pyx +549 -0
- cchecksum/keccak.c +127 -0
- cchecksum/keccak.h +8 -0
- cchecksum/monkey_patch.py +47 -0
- cchecksum/py.typed +0 -0
- cchecksum-0.4.0.dist-info/METADATA +50 -0
- cchecksum-0.4.0.dist-info/RECORD +17 -0
- cchecksum-0.4.0.dist-info/WHEEL +7 -0
- cchecksum-0.4.0.dist-info/licenses/LICENSE +21 -0
- cchecksum-0.4.0.dist-info/top_level.txt +2 -0
benchmarks/__init__.py
ADDED
|
File without changes
|
benchmarks/data.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
from binascii import unhexlify
|
|
2
|
+
from typing import Final
|
|
3
|
+
|
|
4
|
+
BASE_ADDRESSES: Final = [
|
|
5
|
+
"0x52908400098527886e0f7030069857d2e4169ee7",
|
|
6
|
+
"0xde709f2102306220921060314715629080e2fb77",
|
|
7
|
+
"0x27b1fdb04752bbc536007a920d24acb045561c26",
|
|
8
|
+
"0x5aeda56215b167893e80b4fe645ba6d5bab767de",
|
|
9
|
+
"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
MIXED_ADDRESSES: Final = [
|
|
13
|
+
"0x52908400098527886E0F7030069857D2E4169EE7",
|
|
14
|
+
"0x8617E340B3D01FA5F11F306F4090FD50E238070D",
|
|
15
|
+
"0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed",
|
|
16
|
+
"0xfb6916095ca1df60bb79ce92ce3ea74c37c5d359",
|
|
17
|
+
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
STR_CASES: Final = []
|
|
21
|
+
STR_CASE_IDS: Final = []
|
|
22
|
+
for index, address in enumerate(BASE_ADDRESSES):
|
|
23
|
+
STR_CASES.append(address)
|
|
24
|
+
STR_CASE_IDS.append(f"lower-0x-{index}")
|
|
25
|
+
|
|
26
|
+
STR_CASES.append(address.upper())
|
|
27
|
+
STR_CASE_IDS.append(f"upper-0x-{index}")
|
|
28
|
+
|
|
29
|
+
STR_CASES.append(address[2:])
|
|
30
|
+
STR_CASE_IDS.append(f"lower-no-0x-{index}")
|
|
31
|
+
|
|
32
|
+
STR_CASES.append(address[2:].upper())
|
|
33
|
+
STR_CASE_IDS.append(f"upper-no-0x-{index}")
|
|
34
|
+
|
|
35
|
+
for index, address in enumerate(MIXED_ADDRESSES):
|
|
36
|
+
STR_CASES.append(address)
|
|
37
|
+
STR_CASE_IDS.append(f"mixed-{index}")
|
|
38
|
+
|
|
39
|
+
BYTES_CASES: Final = [unhexlify(address[2:]) for address in BASE_ADDRESSES]
|
|
40
|
+
BYTES_CASE_IDS: Final = [f"bytes-{index}" for index in range(len(BASE_ADDRESSES))]
|
|
41
|
+
|
|
42
|
+
BYTEARRAY_CASES: Final = [bytearray(address) for address in BYTES_CASES]
|
|
43
|
+
BYTEARRAY_CASE_IDS: Final = [f"bytearray-{index}" for index in range(len(BYTES_CASES))]
|
|
44
|
+
|
|
45
|
+
SINGLE_CASES: Final = STR_CASES + BYTES_CASES + BYTEARRAY_CASES
|
|
46
|
+
SINGLE_CASE_IDS: Final = STR_CASE_IDS + BYTES_CASE_IDS + BYTEARRAY_CASE_IDS
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
CONTAINER_SIZES: Final = 100, 1_000, 10_000
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _build_container(cases: list, size: int) -> list:
|
|
53
|
+
return [cases[index % len(cases)] for index in range(size)]
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
STR_CONTAINER_CASES: Final = [_build_container(STR_CASES, size) for size in CONTAINER_SIZES]
|
|
57
|
+
STR_CONTAINER_CASE_IDS: Final = [f"str-container-{size}" for size in CONTAINER_SIZES]
|
|
58
|
+
|
|
59
|
+
BYTES_CONTAINER_CASES: Final = [_build_container(BYTES_CASES, size) for size in CONTAINER_SIZES]
|
|
60
|
+
BYTES_CONTAINER_CASE_IDS: Final = [f"bytes-container-{size}" for size in CONTAINER_SIZES]
|
|
61
|
+
|
|
62
|
+
BYTEARRAY_CONTAINER_CASES: Final = [
|
|
63
|
+
_build_container(BYTEARRAY_CASES, size) for size in CONTAINER_SIZES
|
|
64
|
+
]
|
|
65
|
+
BYTEARRAY_CONTAINER_CASE_IDS: Final = [f"bytearray-container-{size}" for size in CONTAINER_SIZES]
|
|
66
|
+
|
|
67
|
+
CONTAINER_CASES: Final = STR_CONTAINER_CASES + BYTES_CONTAINER_CASES + BYTEARRAY_CONTAINER_CASES
|
|
68
|
+
CONTAINER_CASE_IDS: Final = (
|
|
69
|
+
STR_CONTAINER_CASE_IDS + BYTES_CONTAINER_CASE_IDS + BYTEARRAY_CONTAINER_CASE_IDS
|
|
70
|
+
)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from pytest_codspeed import BenchmarkFixture
|
|
3
|
+
|
|
4
|
+
from benchmarks.data import CONTAINER_CASES, CONTAINER_CASE_IDS, SINGLE_CASES, SINGLE_CASE_IDS
|
|
5
|
+
from cchecksum import to_checksum_address
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@pytest.mark.benchmark(group="to_checksum_address_str")
|
|
9
|
+
@pytest.mark.parametrize("value", SINGLE_CASES, ids=SINGLE_CASE_IDS)
|
|
10
|
+
def test_to_checksum_address(benchmark: BenchmarkFixture, value: str) -> None:
|
|
11
|
+
@benchmark
|
|
12
|
+
def run_10k():
|
|
13
|
+
for _ in range(10_000):
|
|
14
|
+
to_checksum_address(value)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@pytest.mark.benchmark(group="to_checksum_address_bytes_container")
|
|
18
|
+
@pytest.mark.parametrize("values", CONTAINER_CASES, ids=CONTAINER_CASE_IDS)
|
|
19
|
+
def test_to_checksum_address_multi(benchmark: BenchmarkFixture, values: list[bytes]) -> None:
|
|
20
|
+
@benchmark
|
|
21
|
+
def run_container():
|
|
22
|
+
for value in values:
|
|
23
|
+
to_checksum_address(value)
|
cchecksum/__init__.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""CChecksum is a ~8x faster drop-in replacement for eth_utils.to_checksum_address,
|
|
2
|
+
with the most cpu-intensive part implemented in c.
|
|
3
|
+
|
|
4
|
+
It keeps the exact same API as the existing implementation, exceptions and all.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from cchecksum._checksum import to_checksum_address, to_checksum_address_many
|
|
8
|
+
from cchecksum.monkey_patch import monkey_patch_eth_utils, monkey_patch_web3py
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
"to_checksum_address",
|
|
12
|
+
"to_checksum_address_many",
|
|
13
|
+
"monkey_patch_eth_utils",
|
|
14
|
+
"monkey_patch_web3py",
|
|
15
|
+
]
|