Yet another implementation of AtomicLong
Project description
Yet another implementation of AtomicLong class.
Introduction
Class that allows to update long value atomically. Highly inspired by Java’s AtomicLong class and atomic package. The most of performance is gained by using Cython with the pure Python fallback available (you do not want to use it).
Examples:
>> counter = atomicl.AtomicLong() >> counter += 2 >> counter.value 2 >> counter.get_and_set(5) 2 >> counter.value 5
Differences from atomic
atomic is a more mature library and is battle-tested.
Despite small API differences, the huge difference between atomic and atomicl is comparisons operations support. atomicl does not supports comparison and, for now, I do not see reasons to have it. I tend to agree with folks from java on this topic.
atomic is backed by CFFI which makes it a good choice for CPython and PyPy. atomicl with Cython extension gains better performance on CPython and performs worse on PyPy. See Benchmarks for more details.
Benchmarks
Results for benchmarks.py on OS X 10.13.5 with Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz and turbo boost disabled:
Python 3.7.0:
# atomic / atomicl (Cython) ctor_default: Mean +- std dev: [atomic.py37] 1.50 us +- 0.04 us -> [atomicl_cy.py37] 92.3 ns +- 0.9 ns: 16.25x faster (-94%) ctor: Mean +- std dev: [atomic.py37] 1.40 us +- 0.02 us -> [atomicl_cy.py37] 109 ns +- 1 ns: 12.90x faster (-92%) increment: Mean +- std dev: [atomic.py37] 515 ns +- 7 ns -> [atomicl_cy.py37] 33.3 ns +- 0.3 ns: 15.43x faster (-94%) decrement: Mean +- std dev: [atomic.py37] 516 ns +- 6 ns -> [atomicl_cy.py37] 33.3 ns +- 0.2 ns: 15.51x faster (-94%) setter: Mean +- std dev: [atomic.py37] 1.56 us +- 0.02 us -> [atomicl_cy.py37] 42.0 ns +- 0.6 ns: 37.05x faster (-97%) cas: Mean +- std dev: [atomic.py37] 1.68 us +- 0.02 us -> [atomicl_cy.py37] 137 ns +- 1 ns: 12.30x faster (-92%) # atomic / atomicl (Python) ctor_default: Mean +- std dev: [atomic.py37] 1.50 us +- 0.04 us -> [atomicl_py.py37] 957 ns +- 17 ns: 1.57x faster (-36%) ctor: Mean +- std dev: [atomic.py37] 1.40 us +- 0.02 us -> [atomicl_py.py37] 902 ns +- 17 ns: 1.56x faster (-36%) increment: Mean +- std dev: [atomic.py37] 515 ns +- 7 ns -> [atomicl_py.py37] 980 ns +- 60 ns: 1.90x slower (+90%) decrement: Mean +- std dev: [atomic.py37] 516 ns +- 6 ns -> [atomicl_py.py37] 970 ns +- 26 ns: 1.88x slower (+88%) setter: Mean +- std dev: [atomic.py37] 1.56 us +- 0.02 us -> [atomicl_py.py37] 413 ns +- 12 ns: 3.77x faster (-73%) cas: Mean +- std dev: [atomic.py37] 1.68 us +- 0.02 us -> [atomicl_py.py37] 1.03 us +- 0.01 us: 1.64x faster (-39%)
Python 3.4.6:
# atomic / atomicl (Cython) ctor_default: Mean +- std dev: [atomic.py34] 1.64 us +- 0.06 us -> [atomicl_cy.py34] 74.5 ns +- 0.8 ns: 22.03x faster (-95%) ctor: Mean +- std dev: [atomic.py34] 1.52 us +- 0.03 us -> [atomicl_cy.py34] 90.9 ns +- 1.1 ns: 16.71x faster (-94%) increment: Mean +- std dev: [atomic.py34] 523 ns +- 20 ns -> [atomicl_cy.py34] 33.3 ns +- 0.3 ns: 15.70x faster (-94%) decrement: Mean +- std dev: [atomic.py34] 522 ns +- 7 ns -> [atomicl_cy.py34] 33.6 ns +- 0.3 ns: 15.55x faster (-94%) setter: Mean +- std dev: [atomic.py34] 1.42 us +- 0.04 us -> [atomicl_cy.py34] 44.0 ns +- 1.1 ns: 32.37x faster (-97%) cas: Mean +- std dev: [atomic.py34] 1.54 us +- 0.03 us -> [atomicl_cy.py34] 118 ns +- 1 ns: 13.05x faster (-92%) # atomic / atomicl (Python) ctor_default: Mean +- std dev: [atomic.py34] 1.64 us +- 0.06 us -> [atomicl_py.py34] 982 ns +- 28 ns: 1.67x faster (-40%) ctor: Mean +- std dev: [atomic.py34] 1.52 us +- 0.03 us -> [atomicl_py.py34] 912 ns +- 24 ns: 1.67x faster (-40%) increment: Mean +- std dev: [atomic.py34] 523 ns +- 20 ns -> [atomicl_py.py34] 1.09 us +- 0.02 us: 2.09x slower (+109%) decrement: Mean +- std dev: [atomic.py34] 522 ns +- 7 ns -> [atomicl_py.py34] 1.10 us +- 0.02 us: 2.11x slower (+111%) setter: Mean +- std dev: [atomic.py34] 1.42 us +- 0.04 us -> [atomicl_py.py34] 456 ns +- 6 ns: 3.12x faster (-68%) cas: Mean +- std dev: [atomic.py34] 1.54 us +- 0.03 us -> [atomicl_py.py34] 1.04 us +- 0.02 us: 1.48x faster (-33%)
PyPy 5.8.0-6.0.0:
# atomic / atomicl (Cython) ctor_default: Mean +- std dev: [atomic.pypy3] 292 ns +- 7 ns -> [atomicl_cy.pypy3] 1.20 us +- 0.04 us: 4.10x slower (+310%) ctor: Mean +- std dev: [atomic.pypy3] 270 ns +- 10 ns -> [atomicl_cy.pypy3] 1.13 us +- 0.03 us: 4.19x slower (+319%) increment: Mean +- std dev: [atomic.pypy3] 27.9 ns +- 0.4 ns -> [atomicl_cy.pypy3] 68.4 ns +- 2.8 ns: 2.45x slower (+145%) decrement: Mean +- std dev: [atomic.pypy3] 27.7 ns +- 0.1 ns -> [atomicl_cy.pypy3] 67.6 ns +- 1.0 ns: 2.44x slower (+144%) setter: Mean +- std dev: [atomic.pypy3] 283 ns +- 5 ns -> [atomicl_cy.pypy3] 49.4 ns +- 1.3 ns: 5.73x faster (-83%) cas: Mean +- std dev: [atomic.pypy3] 289 ns +- 6 ns -> [atomicl_cy.pypy3] 142 ns +- 7 ns: 2.03x faster (-51%) # atomic / atomicl (Python) ctor_default: Mean +- std dev: [atomic.pypy3] 292 ns +- 7 ns -> [atomicl_py.pypy3] 427 ns +- 12 ns: 1.46x slower (+46%) ctor: Mean +- std dev: [atomic.pypy3] 270 ns +- 10 ns -> [atomicl_py.pypy3] 390 ns +- 10 ns: 1.44x slower (+44%) increment: Mean +- std dev: [atomic.pypy3] 27.9 ns +- 0.4 ns -> [atomicl_py.pypy3] 274 ns +- 2 ns: 9.82x slower (+882%) decrement: Mean +- std dev: [atomic.pypy3] 27.7 ns +- 0.1 ns -> [atomicl_py.pypy3] 283 ns +- 6 ns: 10.19x slower (+919%) setter: Mean +- std dev: [atomic.pypy3] 283 ns +- 5 ns -> [atomicl_py.pypy3] 0.22 ns +- 0.00 ns: 1258.80x faster (-100%) cas: Mean +- std dev: [atomic.pypy3] 289 ns +- 6 ns -> [atomicl_py.pypy3] 268 ns +- 3 ns: 1.08x faster (-7%)
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file atomicl-0.1.1.tar.gz
.
File metadata
- Download URL: atomicl-0.1.1.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a0a5417ed5d6dfc637ed28a7cc7d677a706355f036c074132bc4834afe9fc2d |
|
MD5 | 868e7d391086963bd498930ebbc2c866 |
|
BLAKE2b-256 | 3245ddc23cb19820fa0690697f972c7a87c20b5886cc5600c6c42e61d11be31c |
File details
Details for the file atomicl-0.1.1-cp37-cp37m-manylinux1_x86_64.whl
.
File metadata
- Download URL: atomicl-0.1.1-cp37-cp37m-manylinux1_x86_64.whl
- Upload date:
- Size: 121.6 kB
- Tags: CPython 3.7m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0d0265d04cc33eac458985cf52415e5f165aca7d046dfa20bf615bbd01d3d24 |
|
MD5 | f095fc5bd220e7462fb855cb3bab71cf |
|
BLAKE2b-256 | 983b083b2e5e0e403123769e74d7b9e2165c486fbb2e543a0aecac061115ada3 |
File details
Details for the file atomicl-0.1.1-cp37-cp37m-manylinux1_i686.whl
.
File metadata
- Download URL: atomicl-0.1.1-cp37-cp37m-manylinux1_i686.whl
- Upload date:
- Size: 119.3 kB
- Tags: CPython 3.7m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66cbb615c241dc6bb404ac4e9eb5d2f620c2e8ba36a1046821e0bf55ce8fafd3 |
|
MD5 | 9f31d6f42db898b10b1dfbacbd6f56c4 |
|
BLAKE2b-256 | dc8fc9abcd8b0a336d1bf5e8bbcdaaa1831452783faac0232c11d2443e8e31a4 |
File details
Details for the file atomicl-0.1.1-cp37-cp37m-macosx_10_6_intel.whl
.
File metadata
- Download URL: atomicl-0.1.1-cp37-cp37m-macosx_10_6_intel.whl
- Upload date:
- Size: 84.9 kB
- Tags: CPython 3.7m, macOS 10.6+ intel
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e94fcc00056b3fb372253305c565fe848eef3b1f6e18770ac0dd5e98d13d4069 |
|
MD5 | 19c66a7fe4495effd8c6296d44503e90 |
|
BLAKE2b-256 | ffbd85982aad80bd1c1e0c9917b74feba2326fc47e89dea10344d0bb23015d1e |
File details
Details for the file atomicl-0.1.1-cp36-cp36m-manylinux1_x86_64.whl
.
File metadata
- Download URL: atomicl-0.1.1-cp36-cp36m-manylinux1_x86_64.whl
- Upload date:
- Size: 121.5 kB
- Tags: CPython 3.6m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d39f670e7926cef5df9776131aa68011c10b744428357f6639b8528c7e409bdf |
|
MD5 | e0f8e80c23099cae14a3aba921c4d01c |
|
BLAKE2b-256 | 9732b197ede3d5e8b746d5709ebc785d1734400529c03bfac66817b5ffd8c40b |
File details
Details for the file atomicl-0.1.1-cp36-cp36m-manylinux1_i686.whl
.
File metadata
- Download URL: atomicl-0.1.1-cp36-cp36m-manylinux1_i686.whl
- Upload date:
- Size: 119.0 kB
- Tags: CPython 3.6m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01b81880c07ff9829f586a618a67d347206da4881e2e6b6246fe6a3d9097dc1f |
|
MD5 | 50564c03c03b0241890ae2358807e81a |
|
BLAKE2b-256 | 8314d5e5f203683c8558384ced2a7d4f997fb2cb86b430f50e4de19a215b1dbe |
File details
Details for the file atomicl-0.1.1-cp36-cp36m-macosx_10_6_intel.whl
.
File metadata
- Download URL: atomicl-0.1.1-cp36-cp36m-macosx_10_6_intel.whl
- Upload date:
- Size: 85.0 kB
- Tags: CPython 3.6m, macOS 10.6+ intel
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e7df2b45ab33e97bdabb5c513c7e0d99d2723b7e9687e5ae61d5335754ddba67 |
|
MD5 | 260e88aec0a24b442a48fed8e9f05d0a |
|
BLAKE2b-256 | 094325f6b502d80e43f8b38a3f22d00d7d09930ffda3cf1cff8912deadcf0485 |
File details
Details for the file atomicl-0.1.1-cp35-cp35m-manylinux1_x86_64.whl
.
File metadata
- Download URL: atomicl-0.1.1-cp35-cp35m-manylinux1_x86_64.whl
- Upload date:
- Size: 119.0 kB
- Tags: CPython 3.5m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8b3f59556f46cb170a4aebae240b0143a9691983a427761fe39f7b45be38378 |
|
MD5 | ada016d9648df136d3cf6cebba8544e3 |
|
BLAKE2b-256 | 88127d8f665b78aced7877177be331f1aa124a1d73dcd4e268c3d65403bb6221 |
File details
Details for the file atomicl-0.1.1-cp35-cp35m-manylinux1_i686.whl
.
File metadata
- Download URL: atomicl-0.1.1-cp35-cp35m-manylinux1_i686.whl
- Upload date:
- Size: 116.1 kB
- Tags: CPython 3.5m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0677aca945207fe8c4f33a02ebda27c529818b20d1ea50cab5f25dbd7cd74fa |
|
MD5 | 35ee491835dc7b5cdb3887763b94f7b6 |
|
BLAKE2b-256 | 44906d2e1fb7d97f0e582165f4dcd1f81c47f8029d9a45c18ef39c41a4f9abd9 |
File details
Details for the file atomicl-0.1.1-cp35-cp35m-macosx_10_6_intel.whl
.
File metadata
- Download URL: atomicl-0.1.1-cp35-cp35m-macosx_10_6_intel.whl
- Upload date:
- Size: 83.5 kB
- Tags: CPython 3.5m, macOS 10.6+ intel
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 984876333dfac60a86415894aae741eafabd3f68bc085f3b2f3b5d3aab0f1af4 |
|
MD5 | 94ae81536409511bd57a413924f3faa7 |
|
BLAKE2b-256 | e326c2d0d4942400a334dcf3a80d809485b7ada2d8be4b9fb1ddd34ad4bd23b3 |
File details
Details for the file atomicl-0.1.1-cp34-cp34m-manylinux1_x86_64.whl
.
File metadata
- Download URL: atomicl-0.1.1-cp34-cp34m-manylinux1_x86_64.whl
- Upload date:
- Size: 116.3 kB
- Tags: CPython 3.4m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d370613911bf54abeae8968d70f2b75c6ff362dbf724d04605f466c0e7bb7cbb |
|
MD5 | 57a5a558b365ce4cde6e8a4f16b2f653 |
|
BLAKE2b-256 | 128e63417ba27c484ecdd46452ff19a74599fcb21f89006bfc777e1bb67d50f1 |
File details
Details for the file atomicl-0.1.1-cp34-cp34m-manylinux1_i686.whl
.
File metadata
- Download URL: atomicl-0.1.1-cp34-cp34m-manylinux1_i686.whl
- Upload date:
- Size: 115.4 kB
- Tags: CPython 3.4m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e022418d3a3b3f9d34a46e4796091795926750e9ca99467a42c0b74bf43d5de0 |
|
MD5 | 5933717fd0e73c88d5b571736c1a4f20 |
|
BLAKE2b-256 | d66d27a09392e397c19a7ceece90279efde22ad322e80031dd032c2cb372a436 |
File details
Details for the file atomicl-0.1.1-cp34-cp34m-macosx_10_6_intel.whl
.
File metadata
- Download URL: atomicl-0.1.1-cp34-cp34m-macosx_10_6_intel.whl
- Upload date:
- Size: 82.4 kB
- Tags: CPython 3.4m, macOS 10.6+ intel
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fbfbcd3d79dfd97c246d4c7d0893084a13583365e9e511db47eabcc7da9e9162 |
|
MD5 | 49fb099f9796514bb9419faa78fedb48 |
|
BLAKE2b-256 | f2f8692dceaa32761371f87da7725bab015cd9972ff9bf6b7edf04a0ba1f7ded |