Two candies

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Wed Jan 2 20:07:57 EST 2008


Raymond:

>though you have to be very careful about what you measure, how you measure it, that the system state hasn't changed between measurements, and how your interpret the results).<

Right. This is part of the list of things they teach you to care of
when you want to make experiments in biology, etc, too :-)


>* the list approach takes 4 bytes of memory per entry (pointers to a single object)<

I didn't know this...


>* try adding this one to your test suite: a = array('l', [0]) * n<

Time ago I used to use that way because it was faster, but then later
I have forgotten it :-)
Here are the results:

"Warm" timings, best of 3 (seconds):
     n         #1      #2      #3     #4
 1_000_000   1.98    0.79    1.91   0.08
10_000_000  21.73    7.97   21.13   0.85
30_000_000  70.     28.55   65.3    2.55

Approximate peak MB RAM used:
     n        #1     #2      #3      #4
 1_000_000     9   10.3     6.6     ~6?
10_000_000    60   81      64      ~34?
30_000_000   184  210+    200+    ~119?

This fixes the problem 1 of my original post. I suggest to add a line
to the Python docs of the array module to explain about this way of
creating the uniform array (the second problem regards the regular
expression object).

Bye and thank you,
a bear hug,
bearophile



More information about the Python-list mailing list