Hi folks,
due to a question which came up in the tutor list, I'd like
to ask if somebody can explain the following:
(This is true for Python 1.5 under Win98 and Suse Linux at least)
Remember the size of your machine's main memory in MB.
On my machine, this is 64.
Start a fresh Python session with not many other tasks
active at the same time.
Now, divide the number by 16 and multiply by a million.
>>> my_mb = 64
>>> big = my_mb / 16 * 1000000
>>> big
4000000
(16 is a good guess for one integer entry in a list:
4 bytes the pointer, 12 bytes the object).
Now, create a list of numbers with the half of big,
and count the seconds. Afterwards, delete the list
and again count the seconds.
>>> x=range(big/2)
>>> del x
>>>
This will be quite fast, and the deletion will be somewhat
faster than the creation.
Now for the big WHY?
Do the same with big.
>>> x=range(big)
>>> del x
>>>
On my system, creation takes about 10 times as for big/2,
this is ok. But the del takes at least three times as long.
Besides the fact that integers are never really disposed but
build up a freelist, why is deletion so much slower now?
cheers - chris
--
Christian Tismer :^) <mailto:tismer@appliedbiometrics.com>
Applied Biometrics GmbH : Have a break! Take a ride on Python's
Kaiserin-Augusta-Allee 101 : *Starship* http://starship.python.net
10553 Berlin : PGP key -> http://wwwkeys.pgp.net
PGP Fingerprint E182 71C7 1A9D 66E9 9D15 D3CC D4D7 93E2 1FAE F6DF
we're tired of banana software - shipped green, ripens at home
due to a question which came up in the tutor list, I'd like
to ask if somebody can explain the following:
(This is true for Python 1.5 under Win98 and Suse Linux at least)
Remember the size of your machine's main memory in MB.
On my machine, this is 64.
Start a fresh Python session with not many other tasks
active at the same time.
Now, divide the number by 16 and multiply by a million.
>>> my_mb = 64
>>> big = my_mb / 16 * 1000000
>>> big
4000000
(16 is a good guess for one integer entry in a list:
4 bytes the pointer, 12 bytes the object).
Now, create a list of numbers with the half of big,
and count the seconds. Afterwards, delete the list
and again count the seconds.
>>> x=range(big/2)
>>> del x
>>>
This will be quite fast, and the deletion will be somewhat
faster than the creation.
Now for the big WHY?
Do the same with big.
>>> x=range(big)
>>> del x
>>>
On my system, creation takes about 10 times as for big/2,
this is ok. But the del takes at least three times as long.
Besides the fact that integers are never really disposed but
build up a freelist, why is deletion so much slower now?
cheers - chris
--
Christian Tismer :^) <mailto:tismer@appliedbiometrics.com>
Applied Biometrics GmbH : Have a break! Take a ride on Python's
Kaiserin-Augusta-Allee 101 : *Starship* http://starship.python.net
10553 Berlin : PGP key -> http://wwwkeys.pgp.net
PGP Fingerprint E182 71C7 1A9D 66E9 9D15 D3CC D4D7 93E2 1FAE F6DF
we're tired of banana software - shipped green, ripens at home