[issue21233] Add *Calloc functions to CPython memory allocation API
STINNER Victor
report at bugs.python.org
Mon Apr 28 09:51:02 CEST 2014
STINNER Victor added the comment:
It looks like Windows supports also lazy initialization of memory pages initialized to zero.
According to my microbenchmark on Linux and Windows, only bytes(n) and bytearray(n) are really faster with use_calloc.patch. Most changes of use_calloc.patch are maybe useless since all bytes are initilized to zero, but just after that they are replaced with new bytes.
Results of bench_alloc2.py on Windows 7: original vs calloc-4.patch+use_calloc.patch:
Common platform:
Timer: time.perf_counter
Python unicode implementation: PEP 393
Bits: int=32, long=32, long long=64, size_t=32, void*=32
Platform: Windows-7-6.1.7601-SP1
CFLAGS: None
Timer info: namespace(adjustable=False, implementation='QueryPerformanceCounter(
)', monotonic=True, resolution=1e-08)
Platform of campaign orig:
SCM: hg revision=4b97092aa4bd branch=default date="2014-04-27 18:02 +0100"
Date: 2014-04-28 09:35:30
Python version: 3.5.0a0 (default, Apr 28 2014, 09:33:30) [MSC v.1600 32 bit (Int
el)]
Timer precision: 4.47 us
Platform of campaign calloc:
SCM: hg revision=4f0aaa8804c6 tag=tip branch=default date="2014-04-28 09:27 +020
0"
Date: 2014-04-28 09:37:37
Python version: 3.5.0a0 (default:4f0aaa8804c6, Apr 28 2014, 09:37:03) [MSC v.160
0 32 bit (Intel)]
Timer precision: 4.44 us
-----------------------+-------------+----------------
Tests | orig | calloc
-----------------------+-------------+----------------
object() | 121 ns (*) | 109 ns (-10%)
b'A' * 10 | 77 ns (*) | 79 ns
b'A' * 10**3 | 159 ns (*) | 168 ns (+5%)
b'A' * 10**6 | 428 us (*) | 415 us
'A' * 10 | 87 ns (*) | 89 ns
'A' * 10**3 | 175 ns (*) | 177 ns
'A' * 10**6 | 429 us (*) | 454 us (+6%)
'A' * 10**8 | 48.4 ms (*) | 49 ms
(None,) * 10**0 | 49 ns (*) | 51 ns
(None,) * 10**1 | 115 ns (*) | 99 ns (-14%)
(None,) * 10**2 | 433 ns (*) | 422 ns
(None,) * 10**3 | 3.58 us (*) | 3.57 us
(None,) * 10**4 | 34.9 us (*) | 34.9 us
(None,) * 10**5 | 347 us (*) | 351 us
(None,) * 10**6 | 5.14 ms (*) | 4.85 ms (-6%)
(None,) * 10**7 | 53.2 ms (*) | 50.2 ms (-6%)
(None,) * 10**8 | 563 ms (*) | 515 ms (-9%)
([None] * 10)[1:-1] | 217 ns (*) | 217 ns
([None] * 10**3)[1:-1] | 3.89 us (*) | 3.92 us
([None] * 10**6)[1:-1] | 5.13 ms (*) | 5.17 ms
([None] * 10**8)[1:-1] | 634 ms (*) | 533 ms (-16%)
bytes(10) | 193 ns (*) | 206 ns (+7%)
bytes(10**3) | 266 ns (*) | 296 ns (+12%)
bytes(10**6) | 414 us (*) | 3.89 us (-99%)
bytes(10**8) | 44.2 ms (*) | 4.56 us (-100%)
bytearray(10) | 229 ns (*) | 243 ns (+6%)
bytearray(10**3) | 301 ns (*) | 330 ns (+10%)
bytearray(10**6) | 421 us (*) | 3.89 us (-99%)
bytearray(10**8) | 44.4 ms (*) | 4.56 us (-100%)
-----------------------+-------------+----------------
Total | 1.4 sec (*) | 1.16 sec (-17%)
-----------------------+-------------+----------------
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21233>
_______________________________________
More information about the Python-bugs-list
mailing list