arcrc 0.1.0__tar.gz
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.
- arcrc-0.1.0/PKG-INFO +11 -0
- arcrc-0.1.0/pyproject.toml +24 -0
- arcrc-0.1.0/setup.cfg +4 -0
- arcrc-0.1.0/src/arcrc.egg-info/PKG-INFO +11 -0
- arcrc-0.1.0/src/arcrc.egg-info/SOURCES.txt +8 -0
- arcrc-0.1.0/src/arcrc.egg-info/dependency_links.txt +1 -0
- arcrc-0.1.0/src/arcrc.egg-info/requires.txt +3 -0
- arcrc-0.1.0/src/arcrc.egg-info/top_level.txt +1 -0
- arcrc-0.1.0/src/bench.py +39 -0
- arcrc-0.1.0/tests/test_crc.py +87 -0
arcrc-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: arcrc
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Autosar CRC-8, CRC-16-CCITT und CRC-32 (IEEE) – Runtime- and Tablevariants
|
|
5
|
+
Author: Christoph Schueler
|
|
6
|
+
Project-URL: Homepage, https://github.com/christoph2/arcrc
|
|
7
|
+
Project-URL: Repository, https://github.com/christoph2/arcrc
|
|
8
|
+
Requires-Python: >=3.10
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
Provides-Extra: dev
|
|
11
|
+
Requires-Dist: pytest; extra == "dev"
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
|
|
2
|
+
[project]
|
|
3
|
+
name = "arcrc"
|
|
4
|
+
version = "0.1.0"
|
|
5
|
+
description = "Autosar CRC-8, CRC-16-CCITT und CRC-32 (IEEE) – Runtime- and Tablevariants"
|
|
6
|
+
authors = [
|
|
7
|
+
{ name = "Christoph Schueler" }
|
|
8
|
+
]
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
|
|
12
|
+
[project.urls]
|
|
13
|
+
Homepage = "https://github.com/christoph2/arcrc"
|
|
14
|
+
Repository = "https://github.com/christoph2/arcrc"
|
|
15
|
+
|
|
16
|
+
[project.optional-dependencies]
|
|
17
|
+
dev = ["pytest"]
|
|
18
|
+
|
|
19
|
+
[build-system]
|
|
20
|
+
requires = ["setuptools>=61"]
|
|
21
|
+
build-backend = "setuptools.build_meta"
|
|
22
|
+
|
|
23
|
+
[tool.pytest.ini_options]
|
|
24
|
+
pythonpath = ["src"]
|
arcrc-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: arcrc
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Autosar CRC-8, CRC-16-CCITT und CRC-32 (IEEE) – Runtime- and Tablevariants
|
|
5
|
+
Author: Christoph Schueler
|
|
6
|
+
Project-URL: Homepage, https://github.com/christoph2/arcrc
|
|
7
|
+
Project-URL: Repository, https://github.com/christoph2/arcrc
|
|
8
|
+
Requires-Python: >=3.10
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
Provides-Extra: dev
|
|
11
|
+
Requires-Dist: pytest; extra == "dev"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
bench
|
arcrc-0.1.0/src/bench.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
|
|
2
|
+
import os
|
|
3
|
+
import time
|
|
4
|
+
import arcrc
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def bench(fn, data, loops=200):
|
|
8
|
+
t0 = time.perf_counter()
|
|
9
|
+
for _ in range(loops):
|
|
10
|
+
fn(data)
|
|
11
|
+
t1 = time.perf_counter()
|
|
12
|
+
return (t1 - t0) / loops
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def main():
|
|
16
|
+
sizes = [16, 64, 256, 1024, 4096]
|
|
17
|
+
print("Benchmark: Runtime vs Table\n")
|
|
18
|
+
|
|
19
|
+
for size in sizes:
|
|
20
|
+
data = os.urandom(size)
|
|
21
|
+
print(f"--- {size} bytes ---")
|
|
22
|
+
|
|
23
|
+
print("CRC-8 ",
|
|
24
|
+
f"runtime={bench(crc.crc8_runtime, data)*1e6:8.2f} µs",
|
|
25
|
+
f"table={bench(crc.crc8_table, data)*1e6:8.2f} µs")
|
|
26
|
+
|
|
27
|
+
print("CRC-16",
|
|
28
|
+
f"runtime={bench(crc.crc16_runtime, data)*1e6:8.2f} µs",
|
|
29
|
+
f"table={bench(crc.crc16_table, data)*1e6:8.2f} µs")
|
|
30
|
+
|
|
31
|
+
print("CRC-32",
|
|
32
|
+
f"runtime={bench(crc.crc32_runtime, data)*1e6:8.2f} µs",
|
|
33
|
+
f"table={bench(crc.crc32_table, data)*1e6:8.2f} µs")
|
|
34
|
+
|
|
35
|
+
print()
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
if __name__ == "__main__":
|
|
39
|
+
main()
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
import arcrc as crc
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
CHECK_VECTOR = b"123456789"
|
|
9
|
+
|
|
10
|
+
TEST_DATA = (
|
|
11
|
+
(0x00, 0x00, 0x00, 0x00),
|
|
12
|
+
(0xF2, 0x01, 0x83),
|
|
13
|
+
(0x0F, 0xAA, 0x00, 0x55),
|
|
14
|
+
(0x00, 0xFF, 0x55, 0x11),
|
|
15
|
+
(0x33, 0x22, 0x55, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF),
|
|
16
|
+
(0x92, 0x6B, 0x55),
|
|
17
|
+
(0xFF, 0xFF, 0xFF, 0xFF),
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
EXPECTED_RESULTS = {
|
|
21
|
+
"crc8": (0x59, 0x37, 0x79, 0xB8, 0xCB, 0x8C, 0x74),
|
|
22
|
+
"crc8h2f": (0x12, 0xC2, 0xC6, 0x77, 0x11, 0x33, 0x6C),
|
|
23
|
+
"crc16": (0x84C0, 0xD374, 0x2023, 0xB8F9, 0xF53F, 0x0745, 0x1D0F),
|
|
24
|
+
"crc16_arc": (0x0000, 0xC2E1, 0x0BE3, 0x6CCF, 0xAE98, 0xE24E, 0x9401),
|
|
25
|
+
"crc32": (0x2144DF1C, 0x24AB9D77, 0xB6C9B287, 0x32A06212, 0xB0AE863D, 0x9CDEA29B, 0xFFFFFFFF),
|
|
26
|
+
"crc32p4": (0x6FB32240, 0x4F721A25, 0x20662DF8, 0x9BD7996E, 0xA65A343D, 0xEE688A78, 0xFFFFFFFF),
|
|
27
|
+
"crc64": (
|
|
28
|
+
0xF4A586351E1B9F4B,
|
|
29
|
+
0x319C27668164F1C6,
|
|
30
|
+
0x54C5D0F7667C1575,
|
|
31
|
+
0xA63822BE7E0704E6,
|
|
32
|
+
0x701ECEB219A8E5D5,
|
|
33
|
+
0x5FAA96A9B59F3E4E,
|
|
34
|
+
0xFFFFFFFF00000000,
|
|
35
|
+
),
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
VARIANTS = (
|
|
39
|
+
("crc8_runtime", "crc8_table", EXPECTED_RESULTS["crc8"]),
|
|
40
|
+
("crc8h2f_runtime", "crc8h2f_table", EXPECTED_RESULTS["crc8h2f"]),
|
|
41
|
+
("crc16_runtime", "crc16_table", EXPECTED_RESULTS["crc16"]),
|
|
42
|
+
("crc16_arc_runtime", "crc16_arc_table", EXPECTED_RESULTS["crc16_arc"]),
|
|
43
|
+
("crc32_runtime", "crc32_table", EXPECTED_RESULTS["crc32"]),
|
|
44
|
+
("crc32p4_runtime", "crc32p4_table", EXPECTED_RESULTS["crc32p4"]),
|
|
45
|
+
("crc64_runtime", "crc64_table", EXPECTED_RESULTS["crc64"]),
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
CHECK_EXPECTED = (
|
|
49
|
+
("crc8_runtime", 0x4B),
|
|
50
|
+
("crc8_table", 0x4B),
|
|
51
|
+
("crc8h2f_runtime", 0xDF),
|
|
52
|
+
("crc8h2f_table", 0xDF),
|
|
53
|
+
("crc16_runtime", 0x29B1),
|
|
54
|
+
("crc16_table", 0x29B1),
|
|
55
|
+
("crc16_arc_runtime", 0xBB3D),
|
|
56
|
+
("crc16_arc_table", 0xBB3D),
|
|
57
|
+
("crc32_runtime", 0xCBF43926),
|
|
58
|
+
("crc32_table", 0xCBF43926),
|
|
59
|
+
("crc32p4_runtime", 0x1697D06A),
|
|
60
|
+
("crc32p4_table", 0x1697D06A),
|
|
61
|
+
("crc64_runtime", 0x995DC9BBDF1939FA),
|
|
62
|
+
("crc64_table", 0x995DC9BBDF1939FA),
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
@pytest.mark.parametrize("runtime_name, table_name, expected", VARIANTS)
|
|
67
|
+
def test_known_vectors(runtime_name, table_name, expected):
|
|
68
|
+
runtime_fn = getattr(crc, runtime_name)
|
|
69
|
+
table_fn = getattr(crc, table_name)
|
|
70
|
+
for data, result in zip(TEST_DATA, expected):
|
|
71
|
+
assert runtime_fn(data) == result
|
|
72
|
+
assert table_fn(data) == result
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
@pytest.mark.parametrize("runtime_name, table_name", [(v[0], v[1]) for v in VARIANTS])
|
|
76
|
+
@pytest.mark.parametrize("size", [0, 1, 7, 32, 256, 1024])
|
|
77
|
+
def test_runtime_table_equivalence(runtime_name, table_name, size):
|
|
78
|
+
data = os.urandom(size)
|
|
79
|
+
runtime_fn = getattr(crc, runtime_name)
|
|
80
|
+
table_fn = getattr(crc, table_name)
|
|
81
|
+
assert runtime_fn(data) == table_fn(data)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
@pytest.mark.parametrize("fn_name, expected", CHECK_EXPECTED)
|
|
85
|
+
def test_check_vector(fn_name, expected):
|
|
86
|
+
fn = getattr(crc, fn_name)
|
|
87
|
+
assert fn(CHECK_VECTOR) == expected
|