LISTS: Extract every other element - SUMMARY

Mike Fletcher mfletch at tpresence.com
Sun Dec 19 15:50:49 EST 1999


Was a problem with my testing methodology (profile).  Apparently profile
adds an extra penalty for each function call :( .  Revised testing framework
is below, along with results (that do, indeed, show a significant speedup
for algo7).  Sorry about that. Guess I'll have to stop trusting profile for
my profiling needs :( .

Revised testing algo:

def bigTest( ):
	for exponent in range(1, 7): # up to 10**7 (10 million)
		data = range( 10**exponent)
		print 'DATA LENGTH', len(data)
		for function in [ forMult,forDiv, numReshape, numSlicing,
chrisGiven, chrisInline]:
			avg = []
			for x in range(5):
				t = time.clock()
				function( data )
				avg.append( time.clock()-t )
			print '%s %.4f'%(function, reduce( lambda x,y: x+y,
avg )/len(avg))

p:\>take
DATA LENGTH 10
<function forMult at 810c30> 0.0001
<function forDiv at 810c60> 0.0000
<function numReshape at 810c90> 0.0001
<function numSlicing at 8106f0> 0.0001
<function chrisGiven at 8107a0> 0.0001
<function chrisInline at 8107d0> 0.0001
DATA LENGTH 100
<function forMult at 810c30> 0.0001
<function forDiv at 810c60> 0.0001
<function numReshape at 810c90> 0.0001
<function numSlicing at 8106f0> 0.0001
<function chrisGiven at 8107a0> 0.0002
<function chrisInline at 8107d0> 0.0002
DATA LENGTH 1000
<function forMult at 810c30> 0.0010
<function forDiv at 810c60> 0.0010
<function numReshape at 810c90> 0.0004
<function numSlicing at 8106f0> 0.0005
<function chrisGiven at 8107a0> 0.0006
<function chrisInline at 8107d0> 0.0005
DATA LENGTH 10000
<function forMult at 810c30> 0.0092
<function forDiv at 810c60> 0.0106
<function numReshape at 810c90> 0.0036
<function numSlicing at 8106f0> 0.0035
<function chrisGiven at 8107a0> 0.0051
<function chrisInline at 8107d0> 0.0040
DATA LENGTH 100000
<function forMult at 810c30> 0.1048
<function forDiv at 810c60> 0.1174
<function numReshape at 810c90> 0.0423
<function numSlicing at 8106f0> 0.0429
<function chrisGiven at 8107a0> 0.0625
<function chrisInline at 8107d0> 0.0503
DATA LENGTH 1000000
<function forMult at 810c30> 1.0831
<function forDiv at 810c60> 1.2168
<function numReshape at 810c90> 0.4660
<function numSlicing at 8106f0> 0.4605
<function chrisGiven at 8107a0> 0.6465
<function chrisInline at 8107d0> 0.5405

p:\>
-----Original Message-----
From: Christian Tismer [mailto:tismer at appliedbiometrics.com]
Sent: Sunday, December 19, 1999 3:19 PM
To: Mike Fletcher
Cc: python-list at python.org
Subject: Re: LISTS: Extract every other element - SUMMARY
...
What funny machine/Python do you have ???
Algo 7 is 2.5 times faster on my P200 /Py1.5.2/Windooze.
Here Algo 8 vs. Algo 7: (as expected):

>>> timing(algo7, data, 10)[0]
1.15
>>> timing(algo8, data, 10)[0]
1.1
>>> 
...




More information about the Python-list mailing list