summaryrefslogtreecommitdiff
path: root/lib/protocol_benchmarks.py
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2019-03-27 08:36:58 +0100
committerDaniel Friesel <derf@finalrewind.org>2019-03-27 08:36:58 +0100
commit17111a01af2ed9db8623105c05b8111ba1bc8220 (patch)
tree2025a1d7acda89b1fe152e9ab9fe5c5436747b36 /lib/protocol_benchmarks.py
parentf37aefbdbaf3fab3fe70866c3e624a40be55a54c (diff)
protocol_benchmarks: import lib-to-codegen function; always save timestamps
Diffstat (limited to 'lib/protocol_benchmarks.py')
-rwxr-xr-xlib/protocol_benchmarks.py41
1 files changed, 39 insertions, 2 deletions
diff --git a/lib/protocol_benchmarks.py b/lib/protocol_benchmarks.py
index a1a2350..35e90c6 100755
--- a/lib/protocol_benchmarks.py
+++ b/lib/protocol_benchmarks.py
@@ -5,6 +5,7 @@ import msgpack
import ubjson
import os
+import time
from filelock import FileLock
class DummyProtocol:
@@ -1238,13 +1239,15 @@ class Benchmark:
this_result['data'] = data
if value != None:
this_result[key] = {
- 'v' : value
+ 'v' : value,
+ 'ts' : int(time.time())
}
print('{} {} {} ({}) :: {} -> {}'.format(
libkey, bench_name, bench_index, data, key, value))
else:
this_result[key] = {
- 'e' : error
+ 'e' : error,
+ 'ts' : int(time.time())
}
print('{} {} {} ({}) :: {} -> [E] {}'.format(
libkey, bench_name, bench_index, data, key, error))
@@ -1277,3 +1280,37 @@ class Benchmark:
else:
benchmark_data = {}
return benchmark_data
+
+def codegen_for_lib(library, library_options, data):
+ if library == 'arduinojson':
+ return ArduinoJSON(data, bufsize = 512)
+
+ if library == 'capnproto_c':
+ packed = bool(int(library_options[0]))
+ return CapnProtoC(data, packed = packed)
+
+ if library == 'manualjson':
+ return ManualJSON(data)
+
+ if library == 'modernjson':
+ dataformat, = library_options
+ return ModernJSON(data, dataformat)
+
+ if library == 'mpack':
+ return MPack(data)
+
+ if library == 'nanopb':
+ cardinality, strbuf = library_options
+ if not len(strbuf) or strbuf == '0':
+ strbuf = None
+ else:
+ strbuf = int(strbuf)
+ return NanoPB(data, cardinality = cardinality, max_string_length = strbuf)
+
+ if library == 'ubjson':
+ return UBJ(data)
+
+ if library == 'xdr':
+ return XDR(data)
+
+ raise ValueError('Unsupported library: {}'.format(library))