3 ms·
cpython oddity: The following program (call it "20.py") takes a minute to run, but the reported time for the "x=..." line is a few microseconds. import time
by eesmith 9y ago
cpython oddity: The following program (call it "20.py") takes a minute to run, but the reported time for the "x=..." line is a few microseconds.
import time
if 1:
t1 = time.time()
x = ((((((((0,)*20,)*20,)*20,)*20,)*20,)*20,)*20,)*20
t2 = time.time()
print(t2-t1)
% /usr/bin/time python 20.py
3.09944152832e-06
70.91 real 70.91 user 0.24 sys
- dom0 9y agoThat's probably ARC.
- eesmith 9y agoARC? The GIS language? Age Restricted Content? Advance Reading Copy? Activity-Regulated Cytoskeleton-associated protein?
- dom0 9y agoAutomatic Reference Counting, i.e. garbage collection. That's why the timer wouldn't attribute the CPU time to the line you mention; the GC cleans the structure up when the "x" goes out of scope, so after the timing has ended.
- eesmith 9y agoThanks. No, it's not due to reference counting, at least, not according to the tracker issue which reports this oddity. Add: import os os._exit(0) to the bottom of the code and it still takes a minute to run, even though there's no final garbage collection. Also, that code creates only a few hundred objects, and the 'x' data structure is acyclic.