473,416 Members | 1,869 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Strange timing data for list.pop()

In the recent "transforming a list into a string" thread, we've been
discussing the fact that list.pop() is O(1), but list.pop(0) is O(n). I
decided to do a little timing experiment. To be sure, I did verify
experimentally the expected result, but along the way, I came upon an
interesting artifact that I'm at a loss to explain.

I used the following to generate some timing numbers for pop() on
various sized lists:

import time
for power in range (20):
i = 2 ** power
list = [1] * i
t0 = time.time ()
list.pop ()
t1 = time.time ()
t = t1 - t0
print i, t

I know wall clock time isn't a good way to time things, but it was a
first cut before I dove into the manual and found os.times(). The
interesting thing is the data that I got with the above code:

1 7.70092010498e-05
2 6.91413879395e-06
4 5.96046447754e-06
8 5.00679016113e-06
16 5.00679016113e-06
32 5.00679016113e-06
64 5.00679016113e-06
128 5.00679016113e-06
256 4.05311584473e-06
512 5.00679016113e-06
1024 5.00679016113e-06
2048 5.96046447754e-06
4096 9.05990600586e-06
8192 9.05990600586e-06
16384 9.05990600586e-06
32768 1.4066696167e-05
65536 2.31266021729e-05
131072 3.09944152832e-05
262144 3.60012054443e-05
524288 3.38554382324e-05

I plotted the data. http://www.panix.com/~roy/pop-times.png

An interesting shaped curve! I haven't done any curve fitting, but by
eye it looks something like k - log (1/n). The data is quite
repeatable, too. Admitting that clock time is a silly thing to be
measuring here, anybody have any clue what might be causing this
behavior?

This is on an otherwise idle 768 Mbyte PowerBook running OSX-10.3.4 and
Python 2.3.4.
Jul 18 '05 #1
4 2388

"Roy Smith" <ro*@panix.com> wrote in message
news:ro***********************@reader1.panix.com.. .
In the recent "transforming a list into a string" thread, we've been
discussing the fact that list.pop() is O(1), but list.pop(0) is O(n). I
decided to do a little timing experiment. To be sure, I did verify
experimentally the expected result, but along the way, I came upon an
interesting artifact that I'm at a loss to explain.

I used the following to generate some timing numbers for pop() on
various sized lists:

import time
for power in range (20):
i = 2 ** power
list = [1] * i
t0 = time.time ()
list.pop ()
t1 = time.time ()
t = t1 - t0
print i, t

I know wall clock time isn't a good way to time things, but it was a
first cut before I dove into the manual and found os.times(). The
interesting thing is the data that I got with the above code:

1 7.70092010498e-05
2 6.91413879395e-06
4 5.96046447754e-06
8 5.00679016113e-06
16 5.00679016113e-06
32 5.00679016113e-06
64 5.00679016113e-06
128 5.00679016113e-06
256 4.05311584473e-06
512 5.00679016113e-06
1024 5.00679016113e-06
2048 5.96046447754e-06
4096 9.05990600586e-06
8192 9.05990600586e-06
16384 9.05990600586e-06
32768 1.4066696167e-05
65536 2.31266021729e-05
131072 3.09944152832e-05
262144 3.60012054443e-05
524288 3.38554382324e-05

I plotted the data. http://www.panix.com/~roy/pop-times.png
This appears to be a fitted spline or somesuch rather than the data itself.
Also, the data should better be plotted against power rather than 2**power.
Then you would see a flat region across half the plot.
An interesting shaped curve! I haven't done any curve fitting, but by
eye it looks something like k - log (1/n). The data is quite
repeatable, too. Admitting that clock time is a silly thing to be
measuring here, anybody have any clue what might be causing this
behavior?


cache effect when you exceed 2**10?

Terry J. Reedy


Jul 18 '05 #2
Roy Smith wrote:

anybody have any clue what might be causing this behavior?


Bad experimental setup.

Use the timeit module. Average your measurements.


Jul 18 '05 #3
In article <cM********************@giganews.com>,
Istvan Albert <ia*****@mailblocks.com> wrote:
Roy Smith wrote:

anybody have any clue what might be causing this behavior?


Bad experimental setup.


Of course it was a bad experimental setup. I didn't measure what I set
out to measure. But, I did measure something interesting, and I'm
trying to figure out what it was.
Jul 18 '05 #4
Of course it was a bad experimental setup. I didn't measure what I set
out to measure. But, I did measure something interesting, and I'm
trying to figure out what it was.


That's how some great scientific discoveries were made ;)
Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: John Keeling | last post by:
Dear all, I tried the test program below. My interest is to examine timing differences between insert vs. append & reverse for a list. My results on my XP Python 2.3.4 are as follows:...
3
by: curi42 | last post by:
I am running two functions in a row that do the same thing. One runs in .14 seconds, the other 56. I'm confused. I wrote another version of the program and couldn't get the slow behavior again,...
0
by: john | last post by:
Hi,All Gurus: It is kind of complicated, please bear with me and let me know if you have any questions. Thanks a lot in advance. John I have a csharp method, using emit to dynamically generate...
5
by: Pushkar Pradhan | last post by:
I've decided to use clock() to time my routines, my code is like this: clk1 = clock(); while (n != 1000000) { mm_2r2c_2r2c_bc(&a, &b, &c); n++; } clk2 = clock(); t2 = time(NULL);...
6
by: Mike Kirkpatrick | last post by:
I have this data grid which consists of 3 pick lists. The first pick list is to affect the data binding of the other two. I have figured out how to do the data binding by column. However, I do not...
0
by: Chuck Ritzke | last post by:
I have a page with links that open a second pop-up window to display a chart. I am passing a few data items in hidden fields using a traditional http post (because I can't use a post-back which...
15
by: Jay | last post by:
I have a multi threaded VB.NET application (4 threads) that I use to send text messages to many, many employees via system.timer at a 5 second interval. Basically, I look in a SQL table (queue) to...
5
by: John Fisher | last post by:
I am working on a framework for data acquisition in Python 2.5, am trying to get a structure going more like this: mark start time start event event finishes count time until next interval...
0
by: Daniel Fetchinson | last post by:
On 4/15/08, Daniel Fetchinson <fetchinson@googlemail.comwrote: BTW, using the following ###################################################################### # CODE TO TEST BOTH...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.