# 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.
```python
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
```
Raw data
{
"_id": null,
"home_page": "https://github.com/hansalemaos/cythonfastsort",
"name": "cythonfastsort",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "isin,Cython",
"author": "Johannes Fischer",
"author_email": "aulasparticularesdealemaosp@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/7b/3d/83b7df008b5874a6990c33e8626340e8e6f2365d4c3bf8169f55931de23f/cythonfastsort-0.10.tar.gz",
"platform": null,
"description": "\r\n# C++ parallel sorting algorithms through Cython - up to 8 times faster than NumPy \r\n\r\n## pip install cythonfastsort\r\n\r\n### Tested against Windows / Python 3.11 / Anaconda\r\n\r\n## Cython (and a C/C++ compiler) must be installed to use the optimized Cython implementation.\r\n\r\n\r\n```python\r\n\r\nimport sys\r\nimport timeit\r\nimport numpy as np\r\nfrom cythonfastsort import generate_random_arrays, sort_all\r\n\r\n\r\nsize = 10000000\r\narras = [\r\n (size, \"float32\", -555555555, 555555555),\r\n (size, \"float64\", -100000000000, 100000000000),\r\n (size, np.uint8, 0, 255),\r\n (size, np.int8, -120, 120),\r\n (size, np.int16, -30000, 30000),\r\n (size, np.int32, -555555555, 555555555),\r\n (size, np.int64, -(sys.maxsize-1)//2, (sys.maxsize-1)//2),\r\n (size, np.uint16, 0, 60000),\r\n (size, np.uint32, 0, 555555555),\r\n (size, np.uint64, 0, sys.maxsize-1),\r\n]\r\n\r\nreps = 3\r\nfor a in arras:\r\n arr = generate_random_arrays(*a)\r\n seq = generate_random_arrays(size // 10, *a[1:])\r\n s = \"\"\"u=sort_all(arr)\"\"\"\r\n u = sort_all(arr)\r\n t1 = timeit.timeit(s, globals=globals(), number=reps) / reps\r\n print('c++ ', t1)\r\n s2 = \"\"\"q=np.sort(arr)\"\"\"\r\n q = np.sort(arr)\r\n t2 = timeit.timeit(s2, globals=globals(), number=reps) / reps\r\n print('np ', t2)\r\n print(np.all(q == u))\r\n\r\n print(\"-----------------\")\r\n\r\nhaystack = np.array(\r\n [\r\n b\"Cumings\",\r\n b\"Heikkinen\",\r\n b\"Cumings, Mrs. John Bradley (Florence Briggs Thayer)\",\r\n b\"aaa\",\r\n b\"bbbb()\",\r\n b\"Futrelle\",\r\n b\"Allen\",\r\n b\"Cumings, Mrs. John Bradley (Florence Briggs Thayer)q\",\r\n b\"Braund, Mr. Owen Harris\",\r\n b\"Heikkinen, Miss. Laina\",\r\n b\"Futrelle, Mrs. Jacques Heath (Lily May Peel)\",\r\n b\"Allen, Mr. William Henry\",\r\n b\"Braund\",\r\n ],\r\n dtype=\"S\",\r\n)\r\n\r\narr = np.ascontiguousarray(np.concatenate([haystack for _ in range(200000)]))\r\nreps = 5\r\ns = \"\"\"u=sort_all(arr)\"\"\"\r\nu = sort_all(arr)\r\nt1 = timeit.timeit(s, globals=globals(), number=reps) / reps\r\ns = \"\"\"u=np.sort(arr)\"\"\"\r\nq = np.sort(arr)\r\nt2 = timeit.timeit(s, globals=globals(), number=reps) / reps\r\nprint('c++ ', t1)\r\nprint('np ', t2)\r\nprint(np.all(q == u))\r\n\r\n# c++ 0.2110750000004676\r\n# np 0.6982908999998472\r\n# True\r\n# -----------------\r\n# c++ 0.22871500000110245\r\n# np 0.7115663999999621\r\n# True\r\n# -----------------\r\n# c++ 0.0869510999994721\r\n# np 0.27525126666781335\r\n# True\r\n# -----------------\r\n# c++ 0.09770773333366378\r\n# np 0.28797130000020843\r\n# True\r\n# -----------------\r\n# c++ 0.13066273333364128\r\n# np 0.47454773333326256\r\n# True\r\n# -----------------\r\n# c++ 0.17967379999997016\r\n# np 0.6125306666666196\r\n# True\r\n# -----------------\r\n# c++ 0.19168066666679806\r\n# np 0.6346349666673632\r\n# True\r\n# -----------------\r\n# c++ 0.06744649999988421\r\n# np 0.47243033333264367\r\n# True\r\n# -----------------\r\n# c++ 0.09263499999966977\r\n# np 0.6186357666665572\r\n# True\r\n# -----------------\r\n# c++ 0.11886440000065097\r\n# np 0.6260395666661983\r\n# True\r\n# -----------------\r\n# c++ 0.9570277200000419\r\n# np 1.4337052399998356\r\n# True\r\n\r\n```\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "C++ parallel sorting algorithms through Cython - up to 8 times faster than NumPy",
"version": "0.10",
"project_urls": {
"Homepage": "https://github.com/hansalemaos/cythonfastsort"
},
"split_keywords": [
"isin",
"cython"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "47a1e3efe54cb2c53a1fd61694d5f2af6a0aea0bf2a916e42bf388d9c88aa46d",
"md5": "fe0a0bf2cbd19fac44d554a31696cd89",
"sha256": "7e4fafa75305797502b1c24deeedc0137970d435675f1a316a32d12db80ce8f6"
},
"downloads": -1,
"filename": "cythonfastsort-0.10-py3-none-any.whl",
"has_sig": false,
"md5_digest": "fe0a0bf2cbd19fac44d554a31696cd89",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 23103,
"upload_time": "2023-11-30T19:44:37",
"upload_time_iso_8601": "2023-11-30T19:44:37.876671Z",
"url": "https://files.pythonhosted.org/packages/47/a1/e3efe54cb2c53a1fd61694d5f2af6a0aea0bf2a916e42bf388d9c88aa46d/cythonfastsort-0.10-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "7b3d83b7df008b5874a6990c33e8626340e8e6f2365d4c3bf8169f55931de23f",
"md5": "af2b3a68754275749998e24b336aaf1f",
"sha256": "593d0e814f72e82c11d0f01a85a0e517939052f8394f41b6c3a76e3203dffc0b"
},
"downloads": -1,
"filename": "cythonfastsort-0.10.tar.gz",
"has_sig": false,
"md5_digest": "af2b3a68754275749998e24b336aaf1f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 23287,
"upload_time": "2023-11-30T19:44:39",
"upload_time_iso_8601": "2023-11-30T19:44:39.271526Z",
"url": "https://files.pythonhosted.org/packages/7b/3d/83b7df008b5874a6990c33e8626340e8e6f2365d4c3bf8169f55931de23f/cythonfastsort-0.10.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-11-30 19:44:39",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "hansalemaos",
"github_project": "cythonfastsort",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "cythonfastsort"
}