|
| 1 | +"""CodSpeed benchmarks for uuid-utils""" |
| 2 | +import uuid |
| 3 | + |
| 4 | +import pytest |
| 5 | + |
| 6 | +import uuid_utils |
| 7 | + |
| 8 | +node = uuid.getnode() |
| 9 | + |
| 10 | + |
| 11 | +# UUID Generation Benchmarks |
| 12 | +@pytest.mark.benchmark |
| 13 | +def test_uuid1_stdlib(benchmark): |
| 14 | + """Benchmark stdlib UUID v1 generation""" |
| 15 | + benchmark(lambda: uuid.uuid1(node)) |
| 16 | + |
| 17 | + |
| 18 | +@pytest.mark.benchmark |
| 19 | +def test_uuid1_utils(benchmark): |
| 20 | + """Benchmark uuid_utils UUID v1 generation""" |
| 21 | + benchmark(lambda: uuid_utils.uuid1(node)) |
| 22 | + |
| 23 | + |
| 24 | +@pytest.mark.benchmark |
| 25 | +def test_uuid3_stdlib(benchmark): |
| 26 | + """Benchmark stdlib UUID v3 generation""" |
| 27 | + benchmark(lambda: uuid.uuid3(namespace=uuid.NAMESPACE_DNS, name="python.org")) |
| 28 | + |
| 29 | + |
| 30 | +@pytest.mark.benchmark |
| 31 | +def test_uuid3_utils(benchmark): |
| 32 | + """Benchmark uuid_utils UUID v3 generation""" |
| 33 | + benchmark(lambda: uuid_utils.uuid3(namespace=uuid_utils.NAMESPACE_DNS, name="python.org")) |
| 34 | + |
| 35 | + |
| 36 | +@pytest.mark.benchmark |
| 37 | +def test_uuid4_stdlib(benchmark): |
| 38 | + """Benchmark stdlib UUID v4 generation""" |
| 39 | + benchmark(lambda: uuid.uuid4()) |
| 40 | + |
| 41 | + |
| 42 | +@pytest.mark.benchmark |
| 43 | +def test_uuid4_utils(benchmark): |
| 44 | + """Benchmark uuid_utils UUID v4 generation""" |
| 45 | + benchmark(lambda: uuid_utils.uuid4()) |
| 46 | + |
| 47 | + |
| 48 | +@pytest.mark.benchmark |
| 49 | +def test_uuid5_stdlib(benchmark): |
| 50 | + """Benchmark stdlib UUID v5 generation""" |
| 51 | + benchmark(lambda: uuid.uuid5(namespace=uuid.NAMESPACE_DNS, name="python.org")) |
| 52 | + |
| 53 | + |
| 54 | +@pytest.mark.benchmark |
| 55 | +def test_uuid5_utils(benchmark): |
| 56 | + """Benchmark uuid_utils UUID v5 generation""" |
| 57 | + benchmark(lambda: uuid_utils.uuid5(namespace=uuid_utils.NAMESPACE_DNS, name="python.org")) |
| 58 | + |
| 59 | + |
| 60 | +# UUID Parsing Benchmarks |
| 61 | +@pytest.mark.benchmark |
| 62 | +def test_uuid_from_hex_stdlib(benchmark): |
| 63 | + """Benchmark stdlib UUID from hex string""" |
| 64 | + benchmark(lambda: uuid.UUID("a8098c1a-f86e-11da-bd1a-00112444be1e")) |
| 65 | + |
| 66 | + |
| 67 | +@pytest.mark.benchmark |
| 68 | +def test_uuid_from_hex_utils(benchmark): |
| 69 | + """Benchmark uuid_utils UUID from hex string""" |
| 70 | + benchmark(lambda: uuid_utils.UUID("a8098c1a-f86e-11da-bd1a-00112444be1e")) |
| 71 | + |
| 72 | + |
| 73 | +@pytest.mark.benchmark |
| 74 | +def test_uuid_from_bytes_stdlib(benchmark): |
| 75 | + """Benchmark stdlib UUID from bytes""" |
| 76 | + hex_bytes = bytes.fromhex("a8098c1af86e11dabd1a00112444be1e") |
| 77 | + benchmark(lambda: uuid.UUID(bytes=hex_bytes)) |
| 78 | + |
| 79 | + |
| 80 | +@pytest.mark.benchmark |
| 81 | +def test_uuid_from_bytes_utils(benchmark): |
| 82 | + """Benchmark uuid_utils UUID from bytes""" |
| 83 | + hex_bytes = bytes.fromhex("a8098c1af86e11dabd1a00112444be1e") |
| 84 | + benchmark(lambda: uuid_utils.UUID(bytes=hex_bytes)) |
| 85 | + |
| 86 | + |
| 87 | +@pytest.mark.benchmark |
| 88 | +def test_uuid_from_int_stdlib(benchmark): |
| 89 | + """Benchmark stdlib UUID from int""" |
| 90 | + int_value = 223338299594506624080436508043913872926 |
| 91 | + benchmark(lambda: uuid.UUID(int=int_value)) |
| 92 | + |
| 93 | + |
| 94 | +@pytest.mark.benchmark |
| 95 | +def test_uuid_from_int_utils(benchmark): |
| 96 | + """Benchmark uuid_utils UUID from int""" |
| 97 | + int_value = 223338299594506624080436508043913872926 |
| 98 | + benchmark(lambda: uuid_utils.UUID(int=int_value)) |
| 99 | + |
| 100 | + |
| 101 | +@pytest.mark.benchmark |
| 102 | +def test_uuid_from_fields_stdlib(benchmark): |
| 103 | + """Benchmark stdlib UUID from fields""" |
| 104 | + benchmark(lambda: uuid.UUID(fields=(2819197978, 63598, 4570, 189, 26, 73622928926))) |
| 105 | + |
| 106 | + |
| 107 | +@pytest.mark.benchmark |
| 108 | +def test_uuid_from_fields_utils(benchmark): |
| 109 | + """Benchmark uuid_utils UUID from fields""" |
| 110 | + benchmark(lambda: uuid_utils.UUID(fields=(2819197978, 63598, 4570, 189, 26, 73622928926))) |
0 commit comments