summaryrefslogtreecommitdiffstats
path: root/benchmark
diff options
context:
space:
mode:
authorChristopher Peplin <chris.peplin@rhubarbtech.com>2013-08-22 10:35:35 -0400
committerChristopher Peplin <chris.peplin@rhubarbtech.com>2014-01-07 13:18:09 -0500
commitf85bc9eb9a932988bdab198f9da20c2fea55bac2 (patch)
tree277e761e04bad7b3aa647e9e403d9230bff2d7f7 /benchmark
parente9788f71fb5a4be6bc69605539b0135f0ba1829a (diff)
Add benchmarking tests for binary encoding (moved from cantranslator).
Diffstat (limited to 'benchmark')
-rw-r--r--benchmark/pip-requirements.txt1
-rw-r--r--benchmark/proto/.gitignore1
-rw-r--r--benchmark/proto/compare_sizes.py31
-rwxr-xr-xbenchmark/proto/generate.sh3
-rw-r--r--benchmark/proto/openxc.proto21
5 files changed, 57 insertions, 0 deletions
diff --git a/benchmark/pip-requirements.txt b/benchmark/pip-requirements.txt
new file mode 100644
index 00000000..7f147d92
--- /dev/null
+++ b/benchmark/pip-requirements.txt
@@ -0,0 +1 @@
+protobuf==2.5.0
diff --git a/benchmark/proto/.gitignore b/benchmark/proto/.gitignore
new file mode 100644
index 00000000..0520d7d2
--- /dev/null
+++ b/benchmark/proto/.gitignore
@@ -0,0 +1 @@
+*_pb2.py
diff --git a/benchmark/proto/compare_sizes.py b/benchmark/proto/compare_sizes.py
new file mode 100644
index 00000000..ce6b25b9
--- /dev/null
+++ b/benchmark/proto/compare_sizes.py
@@ -0,0 +1,31 @@
+#!/usr/bin/env python
+
+from __future__ import division
+import sys
+
+import openxc_pb2
+import json
+
+def sizeof_fmt(num):
+ for unit in ['bytes', 'KB', 'MB', 'GB', 'TB']:
+ if num < 1024.0:
+ return "%3.1f%s" % (num, unit)
+ num /= 1024.0
+
+total_json_size = 0
+total_binary_size = 0
+
+trace_file = sys.argv[1]
+for line in open(trace_file):
+ raw_message = json.loads(line)
+ total_json_size += len(json.dumps(raw_message))
+ binary_message = openxc_pb2.RawMessage()
+ binary_message.message_id = raw_message['id']
+ binary_message.data = int(raw_message['data'], 0)
+ total_binary_size += len(binary_message.SerializeToString())
+
+print("For the trace file %s..." % trace_file)
+print("Total transferred JSON size is %s" % sizeof_fmt(total_json_size))
+print("Total transferred binary size is %s" % sizeof_fmt(total_binary_size))
+print("Binary encoding is %f%% smaller than JSON overall" % (
+ 100 - (total_binary_size / total_json_size * 100)))
diff --git a/benchmark/proto/generate.sh b/benchmark/proto/generate.sh
new file mode 100755
index 00000000..576b7b13
--- /dev/null
+++ b/benchmark/proto/generate.sh
@@ -0,0 +1,3 @@
+#!/usr/bin/env bash
+
+protoc -I . --python_out=. openxc.proto
diff --git a/benchmark/proto/openxc.proto b/benchmark/proto/openxc.proto
new file mode 100644
index 00000000..0af663c8
--- /dev/null
+++ b/benchmark/proto/openxc.proto
@@ -0,0 +1,21 @@
+package openxc;
+
+message RawMessage {
+ optional uint32 message_id = 1;
+ optional double data = 2;
+}
+
+message TranslatedStringMessage {
+ optional string name = 1;
+ optional string value = 2;
+}
+
+message TranslatedNumericMessage {
+ optional string name = 1;
+ optional double value = 2;
+}
+
+message TranslatedBooleanMessage {
+ optional string name = 1;
+ optional bool value = 2;
+}