Skip to content

Commit 5096a8b

Browse files
Add CodSpeed for continuous performance monitoring
- Add pytest-codspeed 4.2.0 to requirements.txt - Create comprehensive benchmarks in tests/test_benchmarks.py - Add GitHub Actions workflow for CodSpeed integration - Add CodSpeed badge to README
1 parent 054ff68 commit 5096a8b

File tree

4 files changed

+155
-1
lines changed

4 files changed

+155
-1
lines changed

.github/workflows/codspeed.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: CodSpeed
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: read
12+
id-token: write
13+
14+
env:
15+
RUSTFLAGS: "--cfg uuid_unstable"
16+
17+
jobs:
18+
codspeed:
19+
name: Run benchmarks
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v4
23+
24+
- name: Setup Python
25+
uses: actions/setup-python@v5
26+
with:
27+
python-version: "3.12"
28+
29+
- name: Build Python package with maturin
30+
uses: PyO3/maturin-action@v1
31+
with:
32+
command: develop
33+
args: --release
34+
35+
- name: Install test dependencies
36+
run: pip install -r requirements.txt
37+
38+
- name: Run benchmarks
39+
uses: CodSpeedHQ/action@v4.5.2
40+
with:
41+
mode: simulation
42+
run: pytest tests/test_benchmarks.py --codspeed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
[![Package version](https://badge.fury.io/py/uuid-utils.svg)](https://pypi.org/project/uuid-utils/)
66
[![Supported Python versions](https://img.shields.io/pypi/pyversions/uuid-utils.svg?color=%2334D058)](https://pypi.org/project/uuid-utils)
7+
[![CodSpeed](https://img.shields.io/endpoint?url=https://codspeed.io/badge.json)](https://codspeed.io/aminalaee/uuid-utils?utm_source=badge)
78

89
</div>
910

@@ -93,7 +94,7 @@ os.register_at_fork(uuid_utils.reseed_rng)
9394
## Benchmarks
9495

9596
| Benchmark | Min | Max | Mean | Min (+) | Max (+) | Mean (+) |
96-
|------------------|---------|---------|---------|-----------------|-----------------|-----------------|
97+
|------------------|---------|---------|---------|-----------------|-----------------|--------------------|
9798
| UUID v1 | 0.061 | 0.299 | 0.194 | 0.019 (3.3x) | 0.019 (15.4x) | 0.019 (10.1x) |
9899
| UUID v3 | 0.267 | 0.307 | 0.293 | 0.035 (7.6x) | 0.041 (7.5x) | 0.039 (7.5x) |
99100
| UUID v4 | 0.073 | 0.119 | 0.083 | 0.005 (15.2x) | 0.005 (24.6x) | 0.005 (17.1x) |

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ mkdocs==1.6.1
22
mkdocs-material==9.5.34
33
mypy==1.19.0
44
pytest==9.0.1
5+
pytest-codspeed==4.2.0
56
ruff==0.14.7

tests/test_benchmarks.py

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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

Comments
 (0)