C++ parallel sorting algorithms through Cython - up to 8 times faster than NumPy
pip install cythonfastsort
Tested against Windows / Python 3.11 / Anaconda
Cython (and a C/C++ compiler) must be installed to use the optimized Cython implementation.
import sys
import timeit
import numpy as np
from cythonfastsort import generate_random_arrays, sort_all
size = 10000000
arras = [
(size, "float32", -555555555, 555555555),
(size, "float64", -100000000000, 100000000000),
(size, np.uint8, 0, 255),
(size, np.int8, -120, 120),
(size, np.int16, -30000, 30000),
(size, np.int32, -555555555, 555555555),
(size, np.int64, -(sys.maxsize-1)//2, (sys.maxsize-1)//2),
(size, np.uint16, 0, 60000),
(size, np.uint32, 0, 555555555),
(size, np.uint64, 0, sys.maxsize-1),
]
reps = 3
for a in arras:
arr = generate_random_arrays(*a)
seq = generate_random_arrays(size // 10, *a[1:])
s = """u=sort_all(arr)"""
u = sort_all(arr)
t1 = timeit.timeit(s, globals=globals(), number=reps) / reps
print('c++ ', t1)
s2 = """q=np.sort(arr)"""
q = np.sort(arr)
t2 = timeit.timeit(s2, globals=globals(), number=reps) / reps
print('np ', t2)
print(np.all(q == u))
print("-----------------")
haystack = np.array(
[
b"Cumings",
b"Heikkinen",
b"Cumings, Mrs. John Bradley (Florence Briggs Thayer)",
b"aaa",
b"bbbb()",
b"Futrelle",
b"Allen",
b"Cumings, Mrs. John Bradley (Florence Briggs Thayer)q",
b"Braund, Mr. Owen Harris",
b"Heikkinen, Miss. Laina",
b"Futrelle, Mrs. Jacques Heath (Lily May Peel)",
b"Allen, Mr. William Henry",
b"Braund",
],
dtype="S",
)
arr = np.ascontiguousarray(np.concatenate([haystack for _ in range(200000)]))
reps = 5
s = """u=sort_all(arr)"""
u = sort_all(arr)
t1 = timeit.timeit(s, globals=globals(), number=reps) / reps
s = """u=np.sort(arr)"""
q = np.sort(arr)
t2 = timeit.timeit(s, globals=globals(), number=reps) / reps
print('c++ ', t1)
print('np ', t2)
print(np.all(q == u))
# c++ 0.2110750000004676
# np 0.6982908999998472
# True
# -----------------
# c++ 0.22871500000110245
# np 0.7115663999999621
# True
# -----------------
# c++ 0.0869510999994721
# np 0.27525126666781335
# True
# -----------------
# c++ 0.09770773333366378
# np 0.28797130000020843
# True
# -----------------
# c++ 0.13066273333364128
# np 0.47454773333326256
# True
# -----------------
# c++ 0.17967379999997016
# np 0.6125306666666196
# True
# -----------------
# c++ 0.19168066666679806
# np 0.6346349666673632
# True
# -----------------
# c++ 0.06744649999988421
# np 0.47243033333264367
# True
# -----------------
# c++ 0.09263499999966977
# np 0.6186357666665572
# True
# -----------------
# c++ 0.11886440000065097
# np 0.6260395666661983
# True
# -----------------
# c++ 0.9570277200000419
# np 1.4337052399998356
# True
Metadata
Release files for cythonfastsort 0.10
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cythonfastsort-0.10.tar.gz | 23.3 kB | Without provenance | Details for cythonfastsort-0.10.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cythonfastsort-0.10-py3-none-any.whl | Python 3 | none | any | Details for cythonfastsort-0.10-py3-none-any.whl |
Total release size: 46.4 kB
Release files / cythonfastsort-0.10.tar.gz
| Download URL | cythonfastsort-0.10.tar.gz |
|---|---|
| Size | 23.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
593d0e814f72e82c11d0f01a85a0e517939052f8394f41b6c3a76e3203dffc0b
|
|
BLAKE2b-256 checksum How to use checksums |
7b3d83b7df008b5874a6990c33e8626340e8e6f2365d4c3bf8169f55931de23f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|
Release files / cythonfastsort-0.10-py3-none-any.whl
| Download URL | cythonfastsort-0.10-py3-none-any.whl |
|---|---|
| Size | 23.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7e4fafa75305797502b1c24deeedc0137970d435675f1a316a32d12db80ce8f6
|
|
BLAKE2b-256 checksum How to use checksums |
47a1e3efe54cb2c53a1fd61694d5f2af6a0aea0bf2a916e42bf388d9c88aa46d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|
Security for cythonfastsort 0.10
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.