Sorts int/float 4x faster than numpy by using parallel_sort from C++
the bigger the array, the bigger the difference
pip install npfastsortcpp
It is basically a self-compiling Windows version of https://stackoverflow.com/a/28663374/15096247
Make sure you use the right MSVC C++ x64/x86 build tools (Link at the end of the description)
# import the module:
from npfastsortcpp import parallelsort
# optional (if you want to check if the fast
# version is used)
# If the fast version can not be imported,
# you will see a warning when you call parallelsort
from npfastsortcpp import npfastsortconfig
npfastsortconfig.enablewarning=True
The first time you import the module, you will see this:
______________________________
Compiling ...
If you get an error, download:
https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=Community&channel=Release&version=VS2022&source=VSLandingPage&passive=false&cid=2030
and install: MSVC ..... C++ x64/x86 build tools
______________________________
Compiling C:/Users/Gamer/anaconda3/envs/stopjogo/lib/site-packages/npfastsortcpp/npparallelsortcpp.pyx because it changed.
[1/1] Cythonizing C:/Users/Gamer/anaconda3/envs/stopjogo/lib/site-packages/npfastsortcpp/npparallelsortcpp.pyx
running build_ext
building 'npparallelsortcpp' extension
"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\bin\HostX86\x64\cl.exe" /c /nologo /O2 /W3 /GL /DNDEBUG /MD -IC:\Users\Gamer\anaconda3\envs\stopjogo\include -IC:\Users\Gamer\anaconda3\envs\stopjogo\Include "-IC:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\include" "-IC:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\VS\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\um" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\shared" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\winrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\cppwinrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um" /EHsc /TpC:/Users/Gamer/anaconda3/envs/stopjogo/lib/site-packages/npfastsortcpp/npparallelsortcpp.cpp /Fobuild\temp.win-amd64-cpython-39\Release\Users/Gamer/anaconda3/envs/stopjogo/lib/site-packages/npfastsortcpp/npparallelsortcpp.obj
npparallelsortcpp.cpp
C:/Users/Gamer/anaconda3/envs/stopjogo/lib/site-packages/npfastsortcpp/npparallelsortcpp.cpp(2746): warning C4244: '=': conversion from 'long' to 'char', possible loss of data
"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\bin\HostX86\x64\link.exe" /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:C:\Users\Gamer\anaconda3\envs\stopjogo\libs /LIBPATH:C:\Users\Gamer\anaconda3\envs\stopjogo /LIBPATH:C:\Users\Gamer\anaconda3\envs\stopjogo\PCbuild\amd64 "/LIBPATH:C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\lib\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\lib\um\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.22621.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\\lib\10.0.22621.0\\um\x64" /EXPORT:PyInit_npparallelsortcpp build\temp.win-amd64-cpython-39\Release\Users/Gamer/anaconda3/envs/stopjogo/lib/site-packages/npfastsortcpp/npparallelsortcpp.obj /OUT:C:\Users\Gamer\anaconda3\envs\stopjogo\lib\site-packages\npfastsortcpp\npparallelsortcpp.cp39-win_amd64.pyd /IMPLIB:build\temp.win-amd64-cpython-39\Release\Users/Gamer/anaconda3/envs/stopjogo/lib/site-packages/npfastsortcpp\npparallelsortcpp.cp39-win_amd64.lib
Creating library build\temp.win-amd64-cpython-39\Release\Users/Gamer/anaconda3/envs/stopjogo/lib/site-packages/npfastsortcpp\npparallelsortcpp.cp39-win_amd64.lib and object build\temp.win-amd64-cpython-39\Release\Users/Gamer/anaconda3/envs/stopjogo/lib/site-packages/npfastsortcpp\npparallelsortcpp.cp39-win_amd64.exp
Generating code
Finished generating code
If you get an error, download:
and install:
MSVC ..... C++ x64/x86 build tools
Let's compare numpy and npfastsortcpp
from npfastsortcpp import parallelsort
from time import perf_counter
import numpy as np
arr=np.random.randint(1, 15000000 + 1,size=15000000)
#arr=np.random.randn(5000000)
arr2 = arr.copy()
start=perf_counter()
parallelsort(arr) # Sorting is in place! The function returns None!
print(f'npfastsortcpp: {perf_counter() - start}')
start=perf_counter()
np.sort(arr2)
print(f'numpy: {perf_counter() - start}')
npfastsortcpp: 0.27110049999998864
numpy: 0.9681288999999964
arr=np.random.randn(5000000)
arr2 = arr.copy()
start=perf_counter()
parallelsort(arr) # Sorting is in place! The function returns None!
print(f'npfastsortcpp: {perf_counter() - start}')
start=perf_counter()
np.sort(arr2)
print(f'numpy: {perf_counter() - start}')
npfastsortcpp: 0.11203969999999686
numpy: 0.35269389999999134
Metadata
Release files for npfastsortcpp 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 |
|---|---|---|---|---|
| npfastsortcpp-0.10.tar.gz | 6.0 kB | Without provenance | Details for npfastsortcpp-0.10.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| npfastsortcpp-0.10-py3-none-any.whl | Python 3 | none | any | Details for npfastsortcpp-0.10-py3-none-any.whl |
Total release size: 13.8 kB
Release files / npfastsortcpp-0.10.tar.gz
| Download URL | npfastsortcpp-0.10.tar.gz |
|---|---|
| Size | 6.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dcf876841c97fc5348915e455ea166f6a6a493010abea137e74ee34296bd52e5
|
|
BLAKE2b-256 checksum How to use checksums |
1acf78a461fdb4f957fff8a4592473db6b45a2a3252905ff57b847b5bebe9f64
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Release files / npfastsortcpp-0.10-py3-none-any.whl
| Download URL | npfastsortcpp-0.10-py3-none-any.whl |
|---|---|
| Size | 7.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4cd08a10cbc839f920908450c3ea4efeffaa51c6d1d017876b1cbbde14d0c6f2
|
|
BLAKE2b-256 checksum How to use checksums |
735c7298ea1f71743f503567fe7ac4ebbb7754457a1322b7141f28c50d1f1aa5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Security for npfastsortcpp 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.