On Mar 5, 6:07 am, Jon Skeet <[email protected]> wrote:
> I've just committed the first pass of a benchmarking tool to trunk.
> Everything is under "benchmarks" - see the readme.txt for usage
> guidelines.
Cool :-)
I did a quick port to python(pasted at the end, hopefully it wont be
garbled), my results on a 3.2ghz p4:
% protoc --python_out tmp google_size.proto
% touch tmp/__init__.py
% python ProtoBench.py tmp.google_size_pb2.SizeMessage1
google_message1.dat
Benchmarking tmp.google_size_pb2.SizeMessage1 with file
google_message1.dat
Serialize to string: 25388 iterations in 31.0s 0.18MB/s
Deserialize from string: 19504 iterations in 30.9s 0.14MB/s
with psyco:
% python ProtoBench.py tmp.google_size_pb2.SizeMessage1
google_message1.dat
Benchmarking tmp.google_size_pb2.SizeMessage1 with file
google_message1.dat
Serialize to string: 38763 iterations in 36.0s 0.23MB/s
Deserialize from string: 22180 iterations in 29.6s 0.16MB/s
--
- Justin
import
time
import
sys
import
traceback
#import
psyco
#psyco.full
()
class
ProtoBench:
MIN_SAMPLE_TIME_S =
2
TARGET_TIME_S =
30
def runTest(self, type,
filename):
print "Benchmarking %s with file %s" % (type,
filename)
mod_name, class_name = type.rsplit(".",
1)
try :
__import__
(mod_name)
mod = sys.modules
[mod_name]
clazz = getattr(mod,
class_name)
self.inputData = open(filename).read
()
sampleMessage = clazz
()
sampleMessage.ParseFromString
(self.inputData)
except Exception,
e:
sys.stderr.write("Unable to get default message for %s\n" %
type);
traceback.print_exc
()
return
False
try :
self.benchmark("Serialize to string",
sampleMessage.SerializeToString)
self.benchmark("Deserialize from string", lambda:
sampleMessage.ParseFromString
(self.inputData))
except Exception,
e:
sys.stderr.write("Error: %s\n" %
e)
sys.stderr.write("Detailed exception information:
\n")
traceback.print_exc
()
return
False
return
True
def benchmark(self, name,
action):
iterations =
1
elapsed = self.timeAction(action,
iterations)
while elapsed <
self.MIN_SAMPLE_TIME_S:
iterations *=
2;
elapsed = self.timeAction(action,
iterations)
iterations = int ((self.TARGET_TIME_S / elapsed) *
iterations)
elapsed = self.timeAction(action,
iterations)
print "%s: %d iterations in %0.1fs %0.2fMB/s" %
(
name, iterations,
elapsed,
(iterations * len(self.inputData)/elapsed/
1024/1024)
)
def timeAction(self, action,
iterations):
start = time.clock
()
for _ in xrange
(iterations):
action
()
end = time.clock
()
return end -
start
if __name__ ==
"__main__":
if len(sys.argv) < 3 or len(sys.argv) %2 !
=1:
sys.stderr.write("""Usage: ProtoBench <descriptor type name>
<input
data>
The descriptor type name is the fully-qualified message
name,
e.g.
benchmark.Message1
(You can specify multiple pairs of descriptor type name and input
data.)
\n""")
sys.exit
(1)
pairs = zip(sys.argv[1::2], sys.argv
[2::2])
pb = ProtoBench
()
for type, filename in
pairs:
pb.runTest(type,
filename)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Protocol Buffers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/protobuf?hl=en
-~----------~----~----~----~------~----~------~--~---