Skip to content

Commit 8c0a207

Browse files
Setup CodSpeed (#104)
Co-authored-by: Amin Alaee <amin.alaee.zaviyeh@postnl.nl>
1 parent c3ffe4e commit 8c0a207

File tree

7 files changed

+126
-9
lines changed

7 files changed

+126
-9
lines changed

.github/workflows/ci.yml

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
if: matrix.target == 'x86_64'
5151
run: |
5252
pip install uuid_utils --no-index --find-links dist --force-reinstall
53-
pip install pytest
53+
pip install pytest pytest-codspeed
5454
pytest -v .
5555
- name: Upload wheels
5656
uses: actions/upload-artifact@v4
@@ -86,9 +86,9 @@ jobs:
8686
install: |
8787
apt-get update
8888
apt-get install -y --no-install-recommends python3 python3-pip
89-
pip3 install -U pip pytest
89+
pip install pytest
9090
run: |
91-
pip3 install uuid_utils --no-index --find-links dist/ --force-reinstall
91+
pip install uuid_utils --no-index --find-links dist/ --force-reinstall
9292
pytest -v .
9393
- name: Upload wheels
9494
uses: actions/upload-artifact@v4
@@ -196,7 +196,7 @@ jobs:
196196
- name: Install and test uuid_utils
197197
run: |
198198
pip install uuid_utils --no-index --find-links dist --force-reinstall
199-
pip install pytest
199+
pip install pytest pytest-codspeed
200200
pytest -v .
201201
- name: Upload wheels
202202
uses: actions/upload-artifact@v4
@@ -232,7 +232,7 @@ jobs:
232232
- name: Install and test uuid_utils
233233
run: |
234234
pip install uuid_utils --no-index --find-links dist --force-reinstall
235-
pip install pytest
235+
pip install pytest pytest-codspeed
236236
pytest -v .
237237
- name: Upload wheels
238238
uses: actions/upload-artifact@v4
@@ -260,7 +260,17 @@ jobs:
260260
name: Release
261261
runs-on: ubuntu-latest
262262
if: "startsWith(github.ref, 'refs/tags/')"
263-
needs: [lint, linux, linux-cross, musllinux, musllinux-cross, windows, macos, sdist]
263+
needs:
264+
[
265+
lint,
266+
linux,
267+
linux-cross,
268+
musllinux,
269+
musllinux-cross,
270+
windows,
271+
macos,
272+
sdist,
273+
]
264274
steps:
265275
- uses: actions/download-artifact@v4.1.8
266276
with:

.github/workflows/codspeed.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
- name: Setup Python
24+
uses: actions/setup-python@v5
25+
with:
26+
python-version: "3.12"
27+
- name: Install dependencies
28+
run: pip install -r requirements.txt
29+
- name: Build Python package with maturin
30+
uses: PyO3/maturin-action@v1
31+
with:
32+
args: --release --out dist
33+
- name: Install uuid_utils
34+
run: pip install uuid_utils --no-index --find-links dist --force-reinstall
35+
- name: Run benchmarks
36+
uses: CodSpeedHQ/action@v4.5.2
37+
with:
38+
mode: simulation
39+
run: pytest tests/test_benchmarks.py --codspeed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,5 @@ docs/_build/
7070
.python-version
7171

7272
.ruff_cache
73-
.mypy_cache
73+
.mypy_cache
74+
.codspeed/

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ build:
66

77
.PHONY: format
88
format:
9-
ruff check --fix python/ tests/
109
ruff format python/ tests/
10+
ruff check --fix python/ tests/
1111
cargo fmt
1212

1313
.PHONY: lint

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: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import pytest
2+
import uuid_utils
3+
4+
pytest.importorskip("pytest_codspeed")
5+
6+
7+
@pytest.mark.benchmark
8+
def test_getnode() -> None:
9+
uuid_utils.getnode()
10+
11+
12+
@pytest.mark.benchmark
13+
def test_uuid1_() -> None:
14+
uuid_utils.uuid1()
15+
16+
17+
@pytest.mark.benchmark
18+
def test_uuid3() -> None:
19+
uuid_utils.uuid3(namespace=uuid_utils.NAMESPACE_DNS, name="python.org")
20+
21+
22+
@pytest.mark.benchmark
23+
def test_uuid4() -> None:
24+
uuid_utils.uuid4()
25+
26+
27+
@pytest.mark.benchmark
28+
def test_uuid5() -> None:
29+
uuid_utils.uuid5(namespace=uuid_utils.NAMESPACE_DNS, name="python.org")
30+
31+
32+
@pytest.mark.benchmark
33+
def test_uuid6() -> None:
34+
uuid_utils.uuid6()
35+
36+
37+
@pytest.mark.benchmark
38+
def test_uuid7() -> None:
39+
uuid_utils.uuid7()
40+
41+
42+
@pytest.mark.benchmark
43+
def test_uuid8() -> None:
44+
uuid_utils.uuid8(bytes=b"\x00" * 16)
45+
46+
47+
@pytest.mark.benchmark
48+
def test_uuid_from_hex() -> None:
49+
uuid_utils.UUID("a8098c1a-f86e-11da-bd1a-00112444be1e")
50+
51+
52+
def test_uuid_from_bytes(benchmark) -> None: # type: ignore[no-untyped-def]
53+
hex_bytes = bytes.fromhex("a8098c1af86e11dabd1a00112444be1e")
54+
benchmark(lambda: uuid_utils.UUID(bytes=hex_bytes))
55+
56+
57+
@pytest.mark.benchmark
58+
def test_uuid_from_int() -> None:
59+
int_value = 223338299594506624080436508043913872926
60+
uuid_utils.UUID(int=int_value)
61+
62+
63+
@pytest.mark.benchmark
64+
def test_uuid_from_fields_utils() -> None:
65+
uuid_utils.UUID(fields=(2819197978, 63598, 4570, 189, 26, 73622928926))

0 commit comments

Comments
 (0)