Skip to content

Commit 23f931a

Browse files
authored
Add benchmarks (#182)
1 parent 84b7bc7 commit 23f931a

10 files changed

+315
-88
lines changed

.github/workflows/build.yml

+8-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ concurrency:
1515
cancel-in-progress: true
1616

1717
env:
18+
PYTHON_VERSION: '3.13'
1819
COINCURVE_IGNORE_SYSTEM_LIB: 'ON'
1920
COINCURVE_SECP256K1_STATIC: 'ON'
2021
COINCURVE_CROSS_HOST: ''
@@ -23,7 +24,7 @@ env:
2324
COINCURVE_SECP256K1_STATIC
2425
COINCURVE_CROSS_HOST
2526
CIBW_BEFORE_ALL_MACOS: ./.github/scripts/install-macos-build-deps.sh
26-
CIBW_TEST_REQUIRES: pytest pytest-benchmark
27+
CIBW_TEST_REQUIRES: pytest
2728
CIBW_TEST_COMMAND: >
2829
python -c
2930
"from coincurve import PrivateKey;
@@ -79,8 +80,11 @@ jobs:
7980
name: coverage-${{ matrix.os }}-${{ matrix.python-version }}
8081
path: coverage.xml
8182

82-
- name: Run benchmarks
83-
run: hatch run hatch-test.py${{ matrix.python-version }}:bench
83+
- name: Install uv
84+
uses: astral-sh/setup-uv@v5
85+
86+
- name: Benchmark
87+
run: uv run --python-preference system scripts/bench.py
8488

8589
coverage:
8690
name: Upload coverage
@@ -172,7 +176,7 @@ jobs:
172176

173177
- uses: actions/setup-python@v5
174178
with:
175-
python-version: '3.12'
179+
python-version: ${{ env.PYTHON_VERSION }}
176180

177181
- name: Build wheels
178182
uses: pypa/[email protected]

.github/workflows/verify_conda_build.yml

+7-7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ concurrency:
1515
cancel-in-progress: true
1616

1717
env:
18+
PYTHON_VERSION: '3.12'
1819
COINCURVE_UPSTREAM_REF: __no_upstream__
1920
COINCURVE_IGNORE_SYSTEM_LIB: 'OFF'
2021
COINCURVE_SECP256K1_STATIC: 'OFF'
@@ -25,7 +26,7 @@ env:
2526
COINCURVE_SECP256K1_STATIC
2627
COINCURVE_CROSS_HOST
2728
CIBW_BEFORE_ALL_MACOS: ./.github/scripts/install-macos-build-deps.sh
28-
CIBW_TEST_REQUIRES: pytest pytest-benchmark
29+
CIBW_TEST_REQUIRES: pytest
2930
CIBW_TEST_COMMAND: >
3031
python -c
3132
"from coincurve import PrivateKey;
@@ -44,8 +45,6 @@ jobs:
4445
defaults:
4546
run:
4647
shell: bash -el {0}
47-
env:
48-
PYTHON_VERSION: '3.12'
4948

5049
steps:
5150
- uses: actions/checkout@v4
@@ -70,8 +69,11 @@ jobs:
7069
- name: Run tests
7170
run: LD_LIBRARY_PATH=$CONDA_PREFIX/lib hatch test
7271

73-
- name: Run benchmarks
74-
run: hatch run hatch-test.py${{ env.PYTHON_VERSION }}:bench
72+
- name: Install uv
73+
uses: astral-sh/setup-uv@v5
74+
75+
- name: Benchmark
76+
run: LD_LIBRARY_PATH=$CONDA_PREFIX/lib uv run --python-preference system scripts/bench.py
7577

7678
linux-wheels-standard:
7779
name: Build Linux wheels
@@ -81,8 +83,6 @@ jobs:
8183
defaults:
8284
run:
8385
shell: bash -el {0}
84-
env:
85-
PYTHON_VERSION: '3.12'
8686

8787
steps:
8888
- uses: actions/checkout@v4

.github/workflows/verify_shared_build.yml

+8-7
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ concurrency:
1515
cancel-in-progress: true
1616

1717
env:
18+
PYTHON_VERSION: '3.12'
1819
COINCURVE_IGNORE_SYSTEM_LIB: '1'
1920
# Only 'SHARED' is recognized, any other string means 'not SHARED'
2021
COINCURVE_SECP256K1_BUILD: 'SHARED'
2122
CIBW_ENVIRONMENT_PASS_LINUX: >
2223
COINCURVE_IGNORE_SYSTEM_LIB
2324
COINCURVE_SECP256K1_BUILD
2425
CIBW_BEFORE_ALL_MACOS: ./.github/scripts/install-macos-build-deps.sh
25-
CIBW_TEST_REQUIRES: pytest pytest-benchmark
26+
CIBW_TEST_REQUIRES: pytest
2627
CIBW_TEST_COMMAND: >
2728
python -c
2829
"from coincurve import PrivateKey;
@@ -40,9 +41,6 @@ jobs:
4041
name: Test latest Python
4142
runs-on: ubuntu-latest
4243

43-
env:
44-
PYTHON_VERSION: '3.12'
45-
4644
steps:
4745
- uses: actions/checkout@v4
4846

@@ -67,8 +65,11 @@ jobs:
6765
- name: Run tests
6866
run: hatch test
6967

70-
- name: Run benchmarks
71-
run: hatch run hatch-test.py${{ env.PYTHON_VERSION }}:bench
68+
- name: Install uv
69+
uses: astral-sh/setup-uv@v5
70+
71+
- name: Benchmark
72+
run: uv run --python-preference system scripts/bench.py
7273

7374
linux-wheels-standard:
7475
name: Build Linux wheels
@@ -119,7 +120,7 @@ jobs:
119120

120121
- uses: actions/setup-python@v5
121122
with:
122-
python-version: '3.12'
123+
python-version: ${{ env.PYTHON_VERSION }}
123124

124125
- name: Build wheels
125126
uses: pypa/[email protected]

docs/benchmarks.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Benchmarks
2+
3+
-----
4+
5+
## Setup
6+
7+
Download [Hatch](https://hatch.pypa.io/latest/install/) or [UV](https://docs.astral.sh/uv/getting-started/installation/) in order to run the benchmarks as follows:
8+
9+
```
10+
[hatch|uv] run scripts/bench.py
11+
```
12+
13+
## Results
14+
15+
| Library | Key generation | Signing | Verification | Key export | Key import |
16+
| --- | --- | --- | --- | --- | --- |
17+
| coincurve v20.0.0 | 33.4 | 52.8 | 58.4 | 12.6 | 39.4 |
18+
| [fastecdsa](https://github.com/AntonKueltz/fastecdsa) v3.0.1 | 1319.6 | 1449.5 | 1160.4 | 1402.9 | 15.5 |
19+
20+
!!! note
21+
- the timings are in microseconds
22+
- signing and verification use a 16 KiB message
23+
- the Python version used for the benchmarks is 3.13.x

hatch.toml

-9
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,6 @@ dependencies = ["ruff==0.9.9"]
88

99
[envs.hatch-test]
1010
dev-mode = false
11-
extra-dependencies = [
12-
"pytest-benchmark",
13-
]
14-
[envs.hatch-test.scripts]
15-
run = "pytest{env:HATCH_TEST_ARGS:} --benchmark-skip {args}"
16-
run-cov = "coverage run -m pytest{env:HATCH_TEST_ARGS:} --benchmark-skip {args}"
17-
cov-combine = "coverage combine"
18-
cov-report = "coverage report"
19-
bench = "pytest{env:HATCH_TEST_ARGS:} --benchmark-only --benchmark-sort=name --benchmark-cprofile=tottime {args}"
2011

2112
[envs.types]
2213
dependencies = [

mkdocs.yml

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ nav:
4848
- About: index.md
4949
- Install: install.md
5050
- API Reference: api.md
51+
- Benchmarks: benchmarks.md
5152
- Meta:
5253
- Users: users.md
5354
- History: history.md

pyproject.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@ name = "coincurve"
1313
authors = [
1414
{ name = "Ofek Lev", email = "[email protected]" },
1515
]
16-
description = "Cross-platform Python bindings for libsecp256k1"
16+
description = "Safest and fastest Python library for secp256k1 elliptic curve operations"
1717
keywords = [
1818
"bitcoin",
1919
"crypto",
2020
"cryptocurrency",
21+
"ecdh",
2122
"ecdsa",
2223
"elliptic curves",
2324
"ethereum",
25+
"libsecp256k1",
2426
"secp256k1",
2527
"schnorr",
2628
]

scripts/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Scripts
2+
3+
-----
4+
5+
This directory contains scripts that are used to develop the project.

0 commit comments

Comments
 (0)