Huge dictionary, 1 min to create, 6 to delete
Emile van Sebille
emile at fenx.com
Thu Aug 31 11:14:35 EDT 2000
Interesting. I had used this code to test: (w/timed output
now)
import time
print " ",time.ctime(time.time())
d = {}
for i in xrange(1000000):
d[i] = i
print " ",time.ctime(time.time())
del d
print " ",time.ctime(time.time())
-----------
And got:
Windows:
Thu Aug 31 07:46:37 2000
Thu Aug 31 07:47:18 2000
Thu Aug 31 07:48:18 2000
[linux]$ date; python test.py; date
Thu Aug 31 07:49:56 PDT 2000
Thu Aug 31 07:49:56 2000
Thu Aug 31 07:50:03 2000
Thu Aug 31 07:50:05 2000
Thu Aug 31 07:50:05 PDT 2000
Which shows a significant difference in clean up time on
the windows side. (aha...windoze!)
When you add additional references to the loop, ala:
k = str(i)
v = k + ":" + k
Each one creates a new string, points a label to it,
and repeats, creating and de-refcounting that many
million more items that need to be cleaned up, which
happens when you exit. In a longer running process,
I imagine the timings might not be so bad, as some
of the work will likely have been done before exitting.
Moral: If you're planning a quick exit, don't
accumulate tons of de-referenced items.
Emile van Sebille
emile at fenx.com
-------------------
More information about the Python-list
mailing list