summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Peplin <chris.peplin@rhubarbtech.com>2013-08-22 10:57:48 -0400
committerChristopher Peplin <chris.peplin@rhubarbtech.com>2014-01-07 13:18:09 -0500
commit8f87419564532b304dec7105afe005f85cdec0e1 (patch)
tree7b3c03741824acefe6a01d6371527943cc9ec6eb
parentf85bc9eb9a932988bdab198f9da20c2fea55bac2 (diff)
Benchmark encoding translated messages as binary, too.
Results for all of my trace files: > ./compare_sizes.py ~/ownCloud/OpenXC\ Traces/peplin/**/*.json 1 For the 89 trace files given... Total transferred raw JSON size is 13.3MB Total transferred raw binary size is 2.1MB Total transferred translated JSON size is 791.0MB Total transferred translated binary size is 318.6MB Total transferred JSON size is 804.3MB Total transferred binary size is 320.6MB Binary encoding is 84.328494% smaller than JSON for raw messages Binary encoding is 59.727489% smaller than JSON for translated messages Binary encoding is 60.133196% smaller than JSON overall
-rwxr-xr-x[-rw-r--r--]benchmark/proto/compare_sizes.py56
-rw-r--r--benchmark/proto/openxc.proto3
2 files changed, 48 insertions, 11 deletions
diff --git a/benchmark/proto/compare_sizes.py b/benchmark/proto/compare_sizes.py
index ce6b25b9..b8b79bb9 100644..100755
--- a/benchmark/proto/compare_sizes.py
+++ b/benchmark/proto/compare_sizes.py
@@ -2,6 +2,7 @@
from __future__ import division
import sys
+import numbers
import openxc_pb2
import json
@@ -12,20 +13,53 @@ def sizeof_fmt(num):
return "%3.1f%s" % (num, unit)
num /= 1024.0
-total_json_size = 0
-total_binary_size = 0
+total_raw_json_size = 0
+total_raw_binary_size = 0
+total_translated_json_size = 0
+total_translated_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())
+for trace_file in sys.argv[1:]:
+ for line in open(trace_file):
+ try:
+ json_message = json.loads(line)
+ except ValueError:
+ continue
-print("For the trace file %s..." % trace_file)
+ if 'id' and 'data' in json_message:
+ total_raw_json_size += len(line)
+ binary_message = openxc_pb2.RawMessage()
+ binary_message.message_id = json_message['id']
+ binary_message.data = int(json_message['data'], 0)
+ total_raw_binary_size += len(binary_message.SerializeToString())
+ else:
+ if isinstance(json_message['value'], bool):
+ binary_message = openxc_pb2.TranslatedBooleanMessage()
+ elif isinstance(json_message['value'], numbers.Number):
+ binary_message = openxc_pb2.TranslatedNumericMessage()
+ else:
+ binary_message = openxc_pb2.TranslatedStringMessage()
+ binary_message.name = json_message['name']
+ binary_message.value = json_message['value']
+ total_translated_json_size += len(line)
+ total_translated_binary_size += len(binary_message.SerializeToString())
+
+
+print("For the %d trace files given..." % len(sys.argv[1:]))
+print("Total transferred raw JSON size is %s" % sizeof_fmt(total_raw_json_size))
+print("Total transferred raw binary size is %s" % sizeof_fmt(total_raw_binary_size))
+print("Total transferred translated JSON size is %s" %
+ sizeof_fmt(total_translated_json_size))
+print("Total transferred translated binary size is %s" %
+ sizeof_fmt(total_translated_binary_size))
+
+total_json_size = total_raw_json_size + total_translated_json_size
print("Total transferred JSON size is %s" % sizeof_fmt(total_json_size))
+total_binary_size = total_raw_binary_size + total_translated_binary_size
print("Total transferred binary size is %s" % sizeof_fmt(total_binary_size))
+
+print("Binary encoding is %f%% smaller than JSON for raw messages" % (
+ 100 - (total_raw_binary_size / total_raw_json_size * 100)))
+print("Binary encoding is %f%% smaller than JSON for translated messages" % (
+ 100 - (total_translated_binary_size / total_translated_json_size * 100)))
print("Binary encoding is %f%% smaller than JSON overall" % (
100 - (total_binary_size / total_json_size * 100)))
diff --git a/benchmark/proto/openxc.proto b/benchmark/proto/openxc.proto
index 0af663c8..0e39bb6c 100644
--- a/benchmark/proto/openxc.proto
+++ b/benchmark/proto/openxc.proto
@@ -19,3 +19,6 @@ message TranslatedBooleanMessage {
optional string name = 1;
optional bool value = 2;
}
+
+// TODO we should also consider having an enum type, h aving each specific
+// message defined as a protobuf