473,325 Members | 2,805 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,325 software developers and data experts.

__delitem__ affecting performance

Hi,

I was performing some timing tests on a class that inherits from the
built-in list, and got some curious results:

import timeit

class MyList(list):
def __init__(self):
list.__init__(self)
self[:] = [0,0,0]

def __delitem__(self,index):
print 'deleting'

ml = MyList()

def test():
global ml
ml[0] += 0
ml[1] += 0
ml[2] += 0

t = timeit.Timer("test()","from __main__ import test")
print t.timeit()
>4.11651382676
import timeit

class MyList(list):
def __init__(self):
list.__init__(self)
self[:] = [0,0,0]

ml = MyList()

def test():
global ml
ml[0] += 0
ml[1] += 0
ml[2] += 0

t = timeit.Timer("test()","from __main__ import test")
print t.timeit()
>2.23268591383
Does anybody know why defining __delitem__ is causing the code to run
slower? It is not being called, so I don't see why it would affect
performance. Overriding other sequence operators like __delslice__ does
not exhibit this behavior.

The speed difference doesn't really bother me, but I am curious.

I used Python 2.4 for this test.

-Karl
Oct 19 '06 #1
1 1154
Karl H. wrote:
Does anybody know why defining __delitem__ is causing the code to run
slower? It is not being called, so I don't see why it would affect
performance.
probably because overriding portions of the internal sequence slot API
(tp_as_sequence) means that Python needs to do full dispatch for all
members of that API, instead of keeping things at the C level.

</F>

Oct 19 '06 #2

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

Similar topics

2
by: spamproof2005 | last post by:
Is there a way to copy the structure from one database to another without affecting the actual data? For example, I added new fields and stored procedures to a db in my development environment....
5
by: Ben Sharvy | last post by:
I know I could do it by restricting hover to a class of links (a:hover.actuallyalink) but is there a way that doesn't require me to change every link in every existing html document?
5
by: Paul Reddin | last post by:
Hi, using ROWNUMBER() is affecting the plan of a view very badly... is there a way of writing the following view to ensure rownumber() is done as the last thing done? i.e after the calling...
0
by: Dennis D. | last post by:
How much is the transition to dot net affecting business? Many businesses have been holding on to the old operating systems and even installed Office 97 on XP. Is business (in the US) going to...
0
by: Lars Netzel | last post by:
Hey! I have a an application with MDI children. The main thing is to create projects (frmProject) that you can save.. .you have have many projects open at the same time (MDI children) The...
2
by: dale zhang | last post by:
Not sure if here is the right place to ask but I have trouble to access forums.asp.net. I am using C# in VWD. Goal: I want to add the left and right spaces like http://www.dotnetnuke.com/. if...
3
by: =?Utf-8?B?V2FubmFiZQ==?= | last post by:
When we want to make updates to our application, we have to make sure all users are logged out, or they will get kicked out when we copy a new DLL. Our web application, using the 1.1 framework,...
0
by: fanoftvb | last post by:
Hi, can someone show me how to delete a row from gridview without affecting the database. Thanks.. p.s I'm using vb 2005
6
by: ramyareddy | last post by:
Hi All, I am using MSSQL 2000 and 2005. i have a table memberSecurity with security numer as primary key. I have some data in the table already. Now i want to make secNo as auto increment and...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.