Update benchmarks to not use files for input/output

This commit is contained in:
Jason Paryani
2013-09-22 17:41:01 -07:00
parent d7905ebc80
commit b911582afa
4 changed files with 22 additions and 88 deletions

View File

@@ -5,7 +5,7 @@ import os
print = lambda *x: x
def writeAddressBook(fd):
def writeAddressBook():
addressBook = addressbook.AddressBook()
alice = addressBook.person.add()
@@ -27,12 +27,12 @@ def writeAddressBook(fd):
bobPhones[1].type = addressbook.Person.WORK
message_string = addressBook.SerializeToString()
fd.write(message_string)
return message_string
def printAddressBook(fd):
def printAddressBook(message_string):
addressBook = addressbook.AddressBook()
addressBook.ParseFromString(fd.read())
addressBook.ParseFromString(message_string)
for person in addressBook.person:
print(person.name, ':', person.email)
@@ -43,10 +43,7 @@ def printAddressBook(fd):
if __name__ == '__main__':
for i in range(10000):
f = open('example', 'w')
writeAddressBook(f)
message_string = writeAddressBook()
f = open('example', 'r')
printAddressBook(f)
printAddressBook(message_string)
os.remove('example')