Skip to content

Instantly share code, notes, and snippets.

@inklesspen
Created March 12, 2009 02:27
Show Gist options
  • Save inklesspen/77871 to your computer and use it in GitHub Desktop.
Save inklesspen/77871 to your computer and use it in GitHub Desktop.
from datetime import datetime
from time import clock
# the python docs say to use time.clock() for benchmarking. it returns seconds.
def datetime_period():
testvar2='9.00'
print "Testing with datetime measurement, test variable %s" % testvar2
startTime = datetime.now()
join=[]
filehandle=open('testwriting.txt','w')
for var in range(10000000):
join.append(testvar2)
"".join(join)
print (datetime.now() - startTime) #3.01 seconds
filehandle.write("".join(join))
filehandle.close()
print (datetime.now() - startTime) #8.9 seconds.
def datetime_a():
testvar2='9a00'
print "Testing with datetime measurement, test variable %s" % testvar2
startTime = datetime.now()
join=[]
filehandle=open('testwriting.txt','w')
for var in range(10000000):
join.append(testvar2)
"".join(join)
print (datetime.now() - startTime) #3.01 seconds
filehandle.write("".join(join))
filehandle.close()
print (datetime.now() - startTime) #8.9 seconds.
def clock_period():
testvar2='9.00'
print "Testing with clock measurement, test variable %s" % testvar2
startTime = clock()
join=[]
filehandle=open('testwriting.txt','w')
for var in range(10000000):
join.append(testvar2)
"".join(join)
print (clock() - startTime) #3.01 seconds
filehandle.write("".join(join))
filehandle.close()
print (clock() - startTime) #8.9 seconds.
def clock_a():
testvar2='9a00'
print "Testing with clock measurement, test variable %s" % testvar2
startTime = clock()
join=[]
filehandle=open('testwriting.txt','w')
for var in range(10000000):
join.append(testvar2)
"".join(join)
print (clock() - startTime) #3.01 seconds
filehandle.write("".join(join))
filehandle.close()
print (clock() - startTime) #8.9 seconds.
def main():
datetime_period()
datetime_a()
clock_period()
clock_a()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment