Created
March 12, 2009 02:27
-
-
Save inklesspen/77871 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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