fastuuid7 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.
- fastuuid7-0.1.0/LICENSE +0 -0
- fastuuid7-0.1.0/MANIFEST.in +5 -0
- fastuuid7-0.1.0/PKG-INFO +331 -0
- fastuuid7-0.1.0/README.md +309 -0
- fastuuid7-0.1.0/benchmarks/__init__.py +2 -0
- fastuuid7-0.1.0/benchmarks/benchmark.py +167 -0
- fastuuid7-0.1.0/examples/basic_usage.py +50 -0
- fastuuid7-0.1.0/examples/batch_generation.py +48 -0
- fastuuid7-0.1.0/examples/database_usage.py +65 -0
- fastuuid7-0.1.0/fastuuid7.egg-info/PKG-INFO +331 -0
- fastuuid7-0.1.0/fastuuid7.egg-info/SOURCES.txt +23 -0
- fastuuid7-0.1.0/fastuuid7.egg-info/dependency_links.txt +1 -0
- fastuuid7-0.1.0/fastuuid7.egg-info/requires.txt +5 -0
- fastuuid7-0.1.0/fastuuid7.egg-info/top_level.txt +5 -0
- fastuuid7-0.1.0/pyproject.toml +91 -0
- fastuuid7-0.1.0/setup.cfg +4 -0
- fastuuid7-0.1.0/setup.py +39 -0
- fastuuid7-0.1.0/tests/__init__.py +2 -0
- fastuuid7-0.1.0/tests/test_uuidv7.py +76 -0
- fastuuid7-0.1.0/uuidv7/__init__.py +10 -0
- fastuuid7-0.1.0/uuidv7/uuidv7/__init__.py +11 -0
- fastuuid7-0.1.0/uuidv7/uuidv7_impl/__init__.py +2 -0
- fastuuid7-0.1.0/uuidv7/uuidv7_impl/include/uuid7_gen.h +6 -0
- fastuuid7-0.1.0/uuidv7/uuidv7_impl/src/uuid7_gen.c +37 -0
- fastuuid7-0.1.0/uuidv7/uuidv7_impl/uuid7_gen.c +31 -0
fastuuid7-0.1.0/LICENSE
ADDED
|
File without changes
|
fastuuid7-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fastuuid7
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: UUID v7 generation package using a C library
|
|
5
|
+
Author-email: Pavel Nekrasov <nekrasovp@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/nekrasovp/uuidv7
|
|
8
|
+
Project-URL: Repository, https://github.com/nekrasovp/uuidv7
|
|
9
|
+
Project-URL: Issues, https://github.com/nekrasovp/uuidv7/issues
|
|
10
|
+
Keywords: uuid,uuidv7,uuid-v7,identifier
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: C
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Requires-Python: >=3.8
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Provides-Extra: dev
|
|
18
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
19
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
20
|
+
Requires-Dist: ruff>=0.1.0; extra == "dev"
|
|
21
|
+
Dynamic: license-file
|
|
22
|
+
|
|
23
|
+
# uuidv7
|
|
24
|
+
|
|
25
|
+
[](https://github.com/nekrasovp/uuidv7/actions/workflows/ci.yml)
|
|
26
|
+
[](https://badge.fury.io/py/fastuuid7)
|
|
27
|
+
|
|
28
|
+
A high-performance UUID v7 generation library implemented in C with Python bindings.
|
|
29
|
+
|
|
30
|
+
## Features
|
|
31
|
+
|
|
32
|
+
- Fast UUID v7 generation using C implementation
|
|
33
|
+
- RFC 9562 compliant UUID v7 format
|
|
34
|
+
- Python 3.8+ support
|
|
35
|
+
- Thread-safe implementation
|
|
36
|
+
- **High Performance**: See [Performance Benchmarks](#performance-benchmarks) section below
|
|
37
|
+
- **Usage Examples**: See [Examples](#examples) section and [`examples/`](examples/) directory
|
|
38
|
+
|
|
39
|
+
## Installation
|
|
40
|
+
|
|
41
|
+
### Using uv (recommended)
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
uv pip install fastuuid7
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Using pip
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
pip install fastuuid7
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### From source
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
git clone https://github.com/nekrasovp/uuidv7.git
|
|
57
|
+
cd uuidv7
|
|
58
|
+
uv pip install -e .
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Usage
|
|
62
|
+
|
|
63
|
+
### Basic Usage
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
from uuidv7 import uuid7
|
|
67
|
+
|
|
68
|
+
# Generate a UUID v7 (matches Python's uuid.uuid7() API)
|
|
69
|
+
uuid = uuid7()
|
|
70
|
+
print(uuid) # e.g., "018f1234-5678-7abc-def0-123456789abc"
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
**Note**: The API matches Python's built-in `uuid.uuid7()` function (available in Python 3.14+). See [Python documentation](https://docs.python.org/3/library/uuid.html#uuid.uuid7) for details.
|
|
74
|
+
|
|
75
|
+
### Examples
|
|
76
|
+
|
|
77
|
+
For more detailed usage examples, see the [`examples/`](examples/) directory:
|
|
78
|
+
|
|
79
|
+
- **[Basic Usage](examples/basic_usage.py)** - Simple UUID generation, validation, and performance demo
|
|
80
|
+
- **[Batch Generation](examples/batch_generation.py)** - High-throughput UUID generation and uniqueness verification
|
|
81
|
+
- **[Database Usage](examples/database_usage.py)** - Using UUID v7 as primary keys with time-ordered records
|
|
82
|
+
|
|
83
|
+
**Quick Start:**
|
|
84
|
+
```bash
|
|
85
|
+
# Install the package first (required)
|
|
86
|
+
uv pip install -e .
|
|
87
|
+
|
|
88
|
+
# Run examples using python -m (recommended)
|
|
89
|
+
python -m examples.basic_usage
|
|
90
|
+
python -m examples.batch_generation
|
|
91
|
+
python -m examples.database_usage
|
|
92
|
+
|
|
93
|
+
# Or using uv run
|
|
94
|
+
uv run python -m examples.basic_usage
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
See the [examples README](examples/README.md) for more details.
|
|
98
|
+
|
|
99
|
+
## Development
|
|
100
|
+
|
|
101
|
+
### Setup
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
# Install uv if not already installed
|
|
105
|
+
curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
106
|
+
|
|
107
|
+
# Install dependencies
|
|
108
|
+
uv sync
|
|
109
|
+
|
|
110
|
+
# Install in development mode
|
|
111
|
+
uv pip install -e .
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Running Tests
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
# Using pytest
|
|
118
|
+
uv run pytest
|
|
119
|
+
|
|
120
|
+
# Using uv
|
|
121
|
+
uv run pytest tests/
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Linting and Formatting
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
# Run ruff linter
|
|
128
|
+
uv run ruff check .
|
|
129
|
+
|
|
130
|
+
# Run ruff formatter
|
|
131
|
+
uv run ruff format .
|
|
132
|
+
|
|
133
|
+
# Fix auto-fixable issues
|
|
134
|
+
uv run ruff check --fix .
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Building
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
# Build wheel
|
|
141
|
+
uv build
|
|
142
|
+
|
|
143
|
+
# Build source distribution
|
|
144
|
+
uv build --sdist
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Running Benchmarks
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
# Run performance benchmarks comparing different implementations
|
|
151
|
+
python benchmarks/benchmark.py
|
|
152
|
+
|
|
153
|
+
# Or using uv
|
|
154
|
+
uv run python benchmarks/benchmark.py
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## Performance Benchmarks
|
|
158
|
+
|
|
159
|
+
### Latest Results
|
|
160
|
+
|
|
161
|
+
**Test Environment:**
|
|
162
|
+
- **OS**: Linux 6.8.0-90-generic
|
|
163
|
+
- **CPU**: 13th Gen Intel(R) Core(TM) i7-1360P
|
|
164
|
+
- **Architecture**: x86_64
|
|
165
|
+
- **Python Version**: 3.14.2
|
|
166
|
+
- **Iterations**: 100,000 UUID generations per implementation
|
|
167
|
+
|
|
168
|
+
### Performance Summary
|
|
169
|
+
|
|
170
|
+
| Implementation | UUIDs/sec | Time/UUID (μs) | Relative Speed |
|
|
171
|
+
|----------------|-----------|----------------|----------------|
|
|
172
|
+
| **Our C Implementation (fastuuid7)** | **501,071** | **2.00** | **1.00x** (baseline) |
|
|
173
|
+
| Pure Python Implementation | 48,827 | 20.48 | **10.26x slower** |
|
|
174
|
+
| Python Built-in (`uuid.uuid7`) | 47,122 | 21.22 | **10.63x slower** |
|
|
175
|
+
| uuid7 Library (PyPI) | 30,263 | 33.04 | **16.56x slower** |
|
|
176
|
+
|
|
177
|
+
### Detailed Results
|
|
178
|
+
|
|
179
|
+
#### Our C Implementation (fastuuid7)
|
|
180
|
+
|
|
181
|
+
- **Throughput**: 501,071 UUIDs/second
|
|
182
|
+
- **Latency**: 2.00 microseconds per UUID
|
|
183
|
+
- **Language**: C with Python bindings
|
|
184
|
+
- **Package**: `fastuuid7` on PyPI
|
|
185
|
+
|
|
186
|
+
**Performance Characteristics:**
|
|
187
|
+
- ✅ Compiled C code for maximum performance
|
|
188
|
+
- ✅ Direct system calls (`clock_gettime`) for timestamp generation
|
|
189
|
+
- ✅ Minimal Python overhead
|
|
190
|
+
- ✅ Thread-safe implementation
|
|
191
|
+
|
|
192
|
+
#### Pure Python Implementation
|
|
193
|
+
|
|
194
|
+
- **Throughput**: 48,827 UUIDs/second
|
|
195
|
+
- **Latency**: 20.48 microseconds per UUID
|
|
196
|
+
- **Language**: Pure Python
|
|
197
|
+
|
|
198
|
+
**Performance Characteristics:**
|
|
199
|
+
- Reference implementation for comparison
|
|
200
|
+
- Uses Python's `time.time()` and `random` module
|
|
201
|
+
- Higher overhead due to Python interpreter
|
|
202
|
+
- Suitable for low-volume use cases
|
|
203
|
+
|
|
204
|
+
#### Python Built-in (`uuid.uuid7`)
|
|
205
|
+
|
|
206
|
+
- **Throughput**: 47,122 UUIDs/second
|
|
207
|
+
- **Latency**: 21.22 microseconds per UUID
|
|
208
|
+
- **Language**: C (Python standard library)
|
|
209
|
+
- **Package**: Part of Python 3.14+ standard library
|
|
210
|
+
- **Status**: ✅ Tested and benchmarked
|
|
211
|
+
|
|
212
|
+
**Performance Characteristics:**
|
|
213
|
+
- C-based implementation in Python standard library
|
|
214
|
+
- Similar performance to pure Python implementations
|
|
215
|
+
- Available in Python 3.14+
|
|
216
|
+
- Well-integrated with Python ecosystem
|
|
217
|
+
|
|
218
|
+
#### uuid7 Library (PyPI)
|
|
219
|
+
|
|
220
|
+
- **Throughput**: 30,263 UUIDs/second
|
|
221
|
+
- **Latency**: 33.04 microseconds per UUID
|
|
222
|
+
- **Language**: Pure Python
|
|
223
|
+
- **Package**: [uuid7 on PyPI](https://pypi.org/project/uuid7/) (installed as `uuid_extensions`)
|
|
224
|
+
- **Status**: ✅ Tested and benchmarked
|
|
225
|
+
|
|
226
|
+
**Performance Characteristics:**
|
|
227
|
+
- Pure Python implementation
|
|
228
|
+
- Lower performance compared to other implementations
|
|
229
|
+
- Well-maintained package on PyPI
|
|
230
|
+
|
|
231
|
+
### Speedup Analysis
|
|
232
|
+
|
|
233
|
+
Our C implementation is:
|
|
234
|
+
- **10.26x faster** than the pure Python reference implementation
|
|
235
|
+
- **10.63x faster** than Python's built-in `uuid.uuid7()` (Python 3.14+)
|
|
236
|
+
- **16.56x faster** than the uuid7 library from PyPI
|
|
237
|
+
|
|
238
|
+
This performance advantage comes from:
|
|
239
|
+
1. **Compiled code**: C code compiled to native machine code vs interpreted Python
|
|
240
|
+
2. **Direct system calls**: Using `clock_gettime()` directly without Python overhead
|
|
241
|
+
3. **Efficient memory management**: Pre-allocated buffers, minimal allocations
|
|
242
|
+
4. **Optimized string formatting**: Using `snprintf()` efficiently
|
|
243
|
+
|
|
244
|
+
### Comparison with Other Implementations
|
|
245
|
+
|
|
246
|
+
All major implementations have been benchmarked and results are shown in the Performance Summary table above.
|
|
247
|
+
|
|
248
|
+
### Performance Recommendations
|
|
249
|
+
|
|
250
|
+
**When to Use Our C Implementation:**
|
|
251
|
+
- ✅ High-throughput applications (>100K UUIDs/second)
|
|
252
|
+
- ✅ Performance-critical code paths
|
|
253
|
+
- ✅ Systems requiring maximum UUID generation speed
|
|
254
|
+
- ✅ Applications generating millions of UUIDs
|
|
255
|
+
|
|
256
|
+
**When to Use Pure Python:**
|
|
257
|
+
- ✅ Low-volume use cases (<10K UUIDs/second)
|
|
258
|
+
- ✅ Prototyping and development
|
|
259
|
+
- ✅ Applications where ease of deployment is more important than performance
|
|
260
|
+
- ✅ Environments where C extensions cannot be installed
|
|
261
|
+
|
|
262
|
+
### Running Benchmarks
|
|
263
|
+
|
|
264
|
+
To run benchmarks on your system:
|
|
265
|
+
|
|
266
|
+
```bash
|
|
267
|
+
# Install the package in development mode
|
|
268
|
+
uv pip install -e .
|
|
269
|
+
|
|
270
|
+
# Run benchmarks
|
|
271
|
+
python benchmarks/benchmark.py
|
|
272
|
+
|
|
273
|
+
# Or using uv
|
|
274
|
+
uv run python benchmarks/benchmark.py
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### Benchmark Methodology
|
|
278
|
+
|
|
279
|
+
The benchmark follows these steps:
|
|
280
|
+
|
|
281
|
+
1. **Warmup Phase**: Each implementation runs 1,000 iterations to warm up CPU caches
|
|
282
|
+
2. **Measurement Phase**: 100,000 UUID generations are timed using `time.perf_counter()`
|
|
283
|
+
3. **Validation**: Each generated UUID is validated for:
|
|
284
|
+
- Correct length (36 characters)
|
|
285
|
+
- Correct format (4 hyphens)
|
|
286
|
+
- Valid UUID v7 structure (version field = 7, variant field = 8/9/a/b)
|
|
287
|
+
|
|
288
|
+
**Metrics Calculated:**
|
|
289
|
+
- **UUIDs/second**: Throughput metric showing how many UUIDs can be generated per second
|
|
290
|
+
- **Time/UUID (μs)**: Latency metric showing microseconds per UUID generation
|
|
291
|
+
- **Speedup**: Relative performance compared to the fastest implementation
|
|
292
|
+
|
|
293
|
+
### Other Implementations
|
|
294
|
+
|
|
295
|
+
Additional UUID v7 implementations that exist but were not benchmarked in this test:
|
|
296
|
+
|
|
297
|
+
- **uuid7 Library**:
|
|
298
|
+
- [PyPI package](https://pypi.org/project/uuid7/)
|
|
299
|
+
- Pure Python implementation
|
|
300
|
+
- See [Comparison with Other Implementations](#comparison-with-other-implementations) section above for status
|
|
301
|
+
|
|
302
|
+
**Note**: To add these implementations to benchmarks, install them and run `python benchmarks/benchmark.py`. The benchmark script will automatically detect and test available implementations.
|
|
303
|
+
|
|
304
|
+
## CI/CD
|
|
305
|
+
|
|
306
|
+
This project uses GitHub Actions for continuous integration and deployment:
|
|
307
|
+
|
|
308
|
+
- **CI Pipeline** (`.github/workflows/ci.yml`):
|
|
309
|
+
- Runs tests on Python 3.8, 3.9, 3.10, 3.11, 3.12, and 3.13
|
|
310
|
+
- Runs linting with ruff
|
|
311
|
+
- Builds the package to verify it compiles correctly
|
|
312
|
+
- Triggers on push and pull requests
|
|
313
|
+
|
|
314
|
+
- **Publish Pipeline** (`.github/workflows/publish.yml`):
|
|
315
|
+
- Automatically publishes to PyPI when a new release is created
|
|
316
|
+
- Uses trusted publishing (no API tokens required)
|
|
317
|
+
- Can be manually triggered via workflow_dispatch
|
|
318
|
+
|
|
319
|
+
### Publishing a New Release
|
|
320
|
+
|
|
321
|
+
1. Update the version in `pyproject.toml` and `uuidv7/__init__.py`
|
|
322
|
+
2. Create a new [GitHub Release](https://github.com/nekrasovp/uuidv7/releases/new)
|
|
323
|
+
3. The workflow will automatically build and publish to PyPI
|
|
324
|
+
|
|
325
|
+
## License
|
|
326
|
+
|
|
327
|
+
MIT License - see LICENSE file for details.
|
|
328
|
+
|
|
329
|
+
## Author
|
|
330
|
+
|
|
331
|
+
Pavel Nekrasov
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
# uuidv7
|
|
2
|
+
|
|
3
|
+
[](https://github.com/nekrasovp/uuidv7/actions/workflows/ci.yml)
|
|
4
|
+
[](https://badge.fury.io/py/fastuuid7)
|
|
5
|
+
|
|
6
|
+
A high-performance UUID v7 generation library implemented in C with Python bindings.
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- Fast UUID v7 generation using C implementation
|
|
11
|
+
- RFC 9562 compliant UUID v7 format
|
|
12
|
+
- Python 3.8+ support
|
|
13
|
+
- Thread-safe implementation
|
|
14
|
+
- **High Performance**: See [Performance Benchmarks](#performance-benchmarks) section below
|
|
15
|
+
- **Usage Examples**: See [Examples](#examples) section and [`examples/`](examples/) directory
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
### Using uv (recommended)
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
uv pip install fastuuid7
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Using pip
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install fastuuid7
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### From source
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
git clone https://github.com/nekrasovp/uuidv7.git
|
|
35
|
+
cd uuidv7
|
|
36
|
+
uv pip install -e .
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Usage
|
|
40
|
+
|
|
41
|
+
### Basic Usage
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
from uuidv7 import uuid7
|
|
45
|
+
|
|
46
|
+
# Generate a UUID v7 (matches Python's uuid.uuid7() API)
|
|
47
|
+
uuid = uuid7()
|
|
48
|
+
print(uuid) # e.g., "018f1234-5678-7abc-def0-123456789abc"
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
**Note**: The API matches Python's built-in `uuid.uuid7()` function (available in Python 3.14+). See [Python documentation](https://docs.python.org/3/library/uuid.html#uuid.uuid7) for details.
|
|
52
|
+
|
|
53
|
+
### Examples
|
|
54
|
+
|
|
55
|
+
For more detailed usage examples, see the [`examples/`](examples/) directory:
|
|
56
|
+
|
|
57
|
+
- **[Basic Usage](examples/basic_usage.py)** - Simple UUID generation, validation, and performance demo
|
|
58
|
+
- **[Batch Generation](examples/batch_generation.py)** - High-throughput UUID generation and uniqueness verification
|
|
59
|
+
- **[Database Usage](examples/database_usage.py)** - Using UUID v7 as primary keys with time-ordered records
|
|
60
|
+
|
|
61
|
+
**Quick Start:**
|
|
62
|
+
```bash
|
|
63
|
+
# Install the package first (required)
|
|
64
|
+
uv pip install -e .
|
|
65
|
+
|
|
66
|
+
# Run examples using python -m (recommended)
|
|
67
|
+
python -m examples.basic_usage
|
|
68
|
+
python -m examples.batch_generation
|
|
69
|
+
python -m examples.database_usage
|
|
70
|
+
|
|
71
|
+
# Or using uv run
|
|
72
|
+
uv run python -m examples.basic_usage
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
See the [examples README](examples/README.md) for more details.
|
|
76
|
+
|
|
77
|
+
## Development
|
|
78
|
+
|
|
79
|
+
### Setup
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
# Install uv if not already installed
|
|
83
|
+
curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
84
|
+
|
|
85
|
+
# Install dependencies
|
|
86
|
+
uv sync
|
|
87
|
+
|
|
88
|
+
# Install in development mode
|
|
89
|
+
uv pip install -e .
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Running Tests
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
# Using pytest
|
|
96
|
+
uv run pytest
|
|
97
|
+
|
|
98
|
+
# Using uv
|
|
99
|
+
uv run pytest tests/
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Linting and Formatting
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
# Run ruff linter
|
|
106
|
+
uv run ruff check .
|
|
107
|
+
|
|
108
|
+
# Run ruff formatter
|
|
109
|
+
uv run ruff format .
|
|
110
|
+
|
|
111
|
+
# Fix auto-fixable issues
|
|
112
|
+
uv run ruff check --fix .
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Building
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
# Build wheel
|
|
119
|
+
uv build
|
|
120
|
+
|
|
121
|
+
# Build source distribution
|
|
122
|
+
uv build --sdist
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Running Benchmarks
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
# Run performance benchmarks comparing different implementations
|
|
129
|
+
python benchmarks/benchmark.py
|
|
130
|
+
|
|
131
|
+
# Or using uv
|
|
132
|
+
uv run python benchmarks/benchmark.py
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Performance Benchmarks
|
|
136
|
+
|
|
137
|
+
### Latest Results
|
|
138
|
+
|
|
139
|
+
**Test Environment:**
|
|
140
|
+
- **OS**: Linux 6.8.0-90-generic
|
|
141
|
+
- **CPU**: 13th Gen Intel(R) Core(TM) i7-1360P
|
|
142
|
+
- **Architecture**: x86_64
|
|
143
|
+
- **Python Version**: 3.14.2
|
|
144
|
+
- **Iterations**: 100,000 UUID generations per implementation
|
|
145
|
+
|
|
146
|
+
### Performance Summary
|
|
147
|
+
|
|
148
|
+
| Implementation | UUIDs/sec | Time/UUID (μs) | Relative Speed |
|
|
149
|
+
|----------------|-----------|----------------|----------------|
|
|
150
|
+
| **Our C Implementation (fastuuid7)** | **501,071** | **2.00** | **1.00x** (baseline) |
|
|
151
|
+
| Pure Python Implementation | 48,827 | 20.48 | **10.26x slower** |
|
|
152
|
+
| Python Built-in (`uuid.uuid7`) | 47,122 | 21.22 | **10.63x slower** |
|
|
153
|
+
| uuid7 Library (PyPI) | 30,263 | 33.04 | **16.56x slower** |
|
|
154
|
+
|
|
155
|
+
### Detailed Results
|
|
156
|
+
|
|
157
|
+
#### Our C Implementation (fastuuid7)
|
|
158
|
+
|
|
159
|
+
- **Throughput**: 501,071 UUIDs/second
|
|
160
|
+
- **Latency**: 2.00 microseconds per UUID
|
|
161
|
+
- **Language**: C with Python bindings
|
|
162
|
+
- **Package**: `fastuuid7` on PyPI
|
|
163
|
+
|
|
164
|
+
**Performance Characteristics:**
|
|
165
|
+
- ✅ Compiled C code for maximum performance
|
|
166
|
+
- ✅ Direct system calls (`clock_gettime`) for timestamp generation
|
|
167
|
+
- ✅ Minimal Python overhead
|
|
168
|
+
- ✅ Thread-safe implementation
|
|
169
|
+
|
|
170
|
+
#### Pure Python Implementation
|
|
171
|
+
|
|
172
|
+
- **Throughput**: 48,827 UUIDs/second
|
|
173
|
+
- **Latency**: 20.48 microseconds per UUID
|
|
174
|
+
- **Language**: Pure Python
|
|
175
|
+
|
|
176
|
+
**Performance Characteristics:**
|
|
177
|
+
- Reference implementation for comparison
|
|
178
|
+
- Uses Python's `time.time()` and `random` module
|
|
179
|
+
- Higher overhead due to Python interpreter
|
|
180
|
+
- Suitable for low-volume use cases
|
|
181
|
+
|
|
182
|
+
#### Python Built-in (`uuid.uuid7`)
|
|
183
|
+
|
|
184
|
+
- **Throughput**: 47,122 UUIDs/second
|
|
185
|
+
- **Latency**: 21.22 microseconds per UUID
|
|
186
|
+
- **Language**: C (Python standard library)
|
|
187
|
+
- **Package**: Part of Python 3.14+ standard library
|
|
188
|
+
- **Status**: ✅ Tested and benchmarked
|
|
189
|
+
|
|
190
|
+
**Performance Characteristics:**
|
|
191
|
+
- C-based implementation in Python standard library
|
|
192
|
+
- Similar performance to pure Python implementations
|
|
193
|
+
- Available in Python 3.14+
|
|
194
|
+
- Well-integrated with Python ecosystem
|
|
195
|
+
|
|
196
|
+
#### uuid7 Library (PyPI)
|
|
197
|
+
|
|
198
|
+
- **Throughput**: 30,263 UUIDs/second
|
|
199
|
+
- **Latency**: 33.04 microseconds per UUID
|
|
200
|
+
- **Language**: Pure Python
|
|
201
|
+
- **Package**: [uuid7 on PyPI](https://pypi.org/project/uuid7/) (installed as `uuid_extensions`)
|
|
202
|
+
- **Status**: ✅ Tested and benchmarked
|
|
203
|
+
|
|
204
|
+
**Performance Characteristics:**
|
|
205
|
+
- Pure Python implementation
|
|
206
|
+
- Lower performance compared to other implementations
|
|
207
|
+
- Well-maintained package on PyPI
|
|
208
|
+
|
|
209
|
+
### Speedup Analysis
|
|
210
|
+
|
|
211
|
+
Our C implementation is:
|
|
212
|
+
- **10.26x faster** than the pure Python reference implementation
|
|
213
|
+
- **10.63x faster** than Python's built-in `uuid.uuid7()` (Python 3.14+)
|
|
214
|
+
- **16.56x faster** than the uuid7 library from PyPI
|
|
215
|
+
|
|
216
|
+
This performance advantage comes from:
|
|
217
|
+
1. **Compiled code**: C code compiled to native machine code vs interpreted Python
|
|
218
|
+
2. **Direct system calls**: Using `clock_gettime()` directly without Python overhead
|
|
219
|
+
3. **Efficient memory management**: Pre-allocated buffers, minimal allocations
|
|
220
|
+
4. **Optimized string formatting**: Using `snprintf()` efficiently
|
|
221
|
+
|
|
222
|
+
### Comparison with Other Implementations
|
|
223
|
+
|
|
224
|
+
All major implementations have been benchmarked and results are shown in the Performance Summary table above.
|
|
225
|
+
|
|
226
|
+
### Performance Recommendations
|
|
227
|
+
|
|
228
|
+
**When to Use Our C Implementation:**
|
|
229
|
+
- ✅ High-throughput applications (>100K UUIDs/second)
|
|
230
|
+
- ✅ Performance-critical code paths
|
|
231
|
+
- ✅ Systems requiring maximum UUID generation speed
|
|
232
|
+
- ✅ Applications generating millions of UUIDs
|
|
233
|
+
|
|
234
|
+
**When to Use Pure Python:**
|
|
235
|
+
- ✅ Low-volume use cases (<10K UUIDs/second)
|
|
236
|
+
- ✅ Prototyping and development
|
|
237
|
+
- ✅ Applications where ease of deployment is more important than performance
|
|
238
|
+
- ✅ Environments where C extensions cannot be installed
|
|
239
|
+
|
|
240
|
+
### Running Benchmarks
|
|
241
|
+
|
|
242
|
+
To run benchmarks on your system:
|
|
243
|
+
|
|
244
|
+
```bash
|
|
245
|
+
# Install the package in development mode
|
|
246
|
+
uv pip install -e .
|
|
247
|
+
|
|
248
|
+
# Run benchmarks
|
|
249
|
+
python benchmarks/benchmark.py
|
|
250
|
+
|
|
251
|
+
# Or using uv
|
|
252
|
+
uv run python benchmarks/benchmark.py
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
### Benchmark Methodology
|
|
256
|
+
|
|
257
|
+
The benchmark follows these steps:
|
|
258
|
+
|
|
259
|
+
1. **Warmup Phase**: Each implementation runs 1,000 iterations to warm up CPU caches
|
|
260
|
+
2. **Measurement Phase**: 100,000 UUID generations are timed using `time.perf_counter()`
|
|
261
|
+
3. **Validation**: Each generated UUID is validated for:
|
|
262
|
+
- Correct length (36 characters)
|
|
263
|
+
- Correct format (4 hyphens)
|
|
264
|
+
- Valid UUID v7 structure (version field = 7, variant field = 8/9/a/b)
|
|
265
|
+
|
|
266
|
+
**Metrics Calculated:**
|
|
267
|
+
- **UUIDs/second**: Throughput metric showing how many UUIDs can be generated per second
|
|
268
|
+
- **Time/UUID (μs)**: Latency metric showing microseconds per UUID generation
|
|
269
|
+
- **Speedup**: Relative performance compared to the fastest implementation
|
|
270
|
+
|
|
271
|
+
### Other Implementations
|
|
272
|
+
|
|
273
|
+
Additional UUID v7 implementations that exist but were not benchmarked in this test:
|
|
274
|
+
|
|
275
|
+
- **uuid7 Library**:
|
|
276
|
+
- [PyPI package](https://pypi.org/project/uuid7/)
|
|
277
|
+
- Pure Python implementation
|
|
278
|
+
- See [Comparison with Other Implementations](#comparison-with-other-implementations) section above for status
|
|
279
|
+
|
|
280
|
+
**Note**: To add these implementations to benchmarks, install them and run `python benchmarks/benchmark.py`. The benchmark script will automatically detect and test available implementations.
|
|
281
|
+
|
|
282
|
+
## CI/CD
|
|
283
|
+
|
|
284
|
+
This project uses GitHub Actions for continuous integration and deployment:
|
|
285
|
+
|
|
286
|
+
- **CI Pipeline** (`.github/workflows/ci.yml`):
|
|
287
|
+
- Runs tests on Python 3.8, 3.9, 3.10, 3.11, 3.12, and 3.13
|
|
288
|
+
- Runs linting with ruff
|
|
289
|
+
- Builds the package to verify it compiles correctly
|
|
290
|
+
- Triggers on push and pull requests
|
|
291
|
+
|
|
292
|
+
- **Publish Pipeline** (`.github/workflows/publish.yml`):
|
|
293
|
+
- Automatically publishes to PyPI when a new release is created
|
|
294
|
+
- Uses trusted publishing (no API tokens required)
|
|
295
|
+
- Can be manually triggered via workflow_dispatch
|
|
296
|
+
|
|
297
|
+
### Publishing a New Release
|
|
298
|
+
|
|
299
|
+
1. Update the version in `pyproject.toml` and `uuidv7/__init__.py`
|
|
300
|
+
2. Create a new [GitHub Release](https://github.com/nekrasovp/uuidv7/releases/new)
|
|
301
|
+
3. The workflow will automatically build and publish to PyPI
|
|
302
|
+
|
|
303
|
+
## License
|
|
304
|
+
|
|
305
|
+
MIT License - see LICENSE file for details.
|
|
306
|
+
|
|
307
|
+
## Author
|
|
308
|
+
|
|
309
|
+
Pavel Nekrasov
|