[IronPython] writing and reading file performance test

smppms2002 smppms2002 at yahoo.com.cn
Sat Apr 29 04:14:57 CEST 2006


I do a writing and reading file performance test, the
result is that python2.3 is more faster than
ironpython1.0 beta6.

test result of python2.3 :
	write & read [00005] M time used:
	w: average=[1.363979] std.deviation=[0.383529]
max=[1.930142] min=[0.961854]
	r: average=[0.682326] std.deviation=[0.467239]
max=[1.382589] min=[0.275619]

test result of ironpython1.6 beta:
	write & read [00005] M time used:
	w: average=[2.488578] std.deviation=[0.223175]
max=[3.054382] min=[2.213188]
	r: average=[1.515179] std.deviation=[0.074947]
max=[1.632347] min=[1.412018]	

bellowing is the test script:

from cStringIO import StringIO
import time
import math

def test_write(m):
	bclock = time.clock() 
	mf = StringIO()
	for i in xrange( 1024*m ):
		mf.write( "*" * 1023 + "\n" )
	f=open("test.txt", "w")
	f.write( mf.getvalue() )
	f.close()
	#mf.close()
	return time.clock() - bclock

def test_read():
	bclock = time.clock() 
	i = 0	
	f=open("test.txt", "r")
	for x in f.readlines():
		i = i + 1
	f.close()
	return time.clock() - bclock

def get_avg( arr ):
	_sum = 0
	for x in arr:
		_sum = _sum + x
	return _sum / len(arr)

def get_test( arr ):
	_dev = 0
	avg =  get_avg( arr )
	for x in arr:	
		_dev = _dev + (avg - x) * (avg - x)
	_dev = math.sqrt( _dev / len( arr ) )
	return  avg, _dev, max(arr), min(arr)
	
if __name__ == "__main__":
	m = 5
	w_arr = []
	r_arr = []
	for i in range(10):
		print ">>> pass ", i + 1
		w_arr.append( test_write(m) )
		r_arr.append( test_read ( )  )
	
	w_avg, w_std_dev, w_max, w_min = get_test( w_arr )
	r_avg, r_std_dev, r_max, r_min = get_test( r_arr )
	
	print "write & read [%05d] M time used:" %( m )
	print "w: average=[%f] std.deviation=[%f] max=[%f]
min=[%f]" % get_test( w_arr )
	print "r: average=[%f] std.deviation=[%f] max=[%f]
min=[%f]" % get_test( r_arr )



	

	
		
___________________________________________________________ 
雅虎1G免费邮箱百分百防垃圾信 
http://cn.mail.yahoo.com/



More information about the Ironpython-users mailing list