diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
commit | 19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch) | |
tree | 42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/jaegertracing/thrift/lib/d/test/serialization_benchmark.d | |
parent | Initial commit. (diff) | |
download | ceph-19fcec84d8d7d21e796c7624e521b60d28ee21ed.tar.xz ceph-19fcec84d8d7d21e796c7624e521b60d28ee21ed.zip |
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/jaegertracing/thrift/lib/d/test/serialization_benchmark.d')
-rw-r--r-- | src/jaegertracing/thrift/lib/d/test/serialization_benchmark.d | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/jaegertracing/thrift/lib/d/test/serialization_benchmark.d b/src/jaegertracing/thrift/lib/d/test/serialization_benchmark.d new file mode 100644 index 000000000..40d048094 --- /dev/null +++ b/src/jaegertracing/thrift/lib/d/test/serialization_benchmark.d @@ -0,0 +1,70 @@ +/** + * An implementation of the mini serialization benchmark also available for + * C++ and Java. + * + * For meaningful results, you might want to make sure that + * the Thrift library is compiled with release build flags, + * e.g. by including the source files with the build instead + * of linking libthriftd: + * + dmd -w -O -release -inline -I../src -Igen-d -ofserialization_benchmark \ + $(find ../src/thrift -name '*.d' -not -name index.d) \ + gen-d/DebugProtoTest_types.d serialization_benchmark.d + */ +module serialization_benchmark; + +import std.datetime.stopwatch : AutoStart, StopWatch; +import std.math : PI; +import std.stdio; +import thrift.protocol.binary; +import thrift.transport.memory; +import thrift.transport.range; +import DebugProtoTest_types; + +void main() { + auto buf = new TMemoryBuffer; + enum ITERATIONS = 10_000_000; + + { + auto ooe = OneOfEach(); + ooe.im_true = true; + ooe.im_false = false; + ooe.a_bite = 0x7f; + ooe.integer16 = 27_000; + ooe.integer32 = 1 << 24; + ooe.integer64 = 6_000_000_000; + ooe.double_precision = PI; + ooe.some_characters = "JSON THIS! \"\1"; + ooe.zomg_unicode = "\xd7\n\a\t"; + ooe.base64 = "\1\2\3\255"; + + auto prot = tBinaryProtocol(buf); + auto sw = StopWatch(AutoStart.yes); + foreach (i; 0 .. ITERATIONS) { + buf.reset(120); + ooe.write(prot); + } + sw.stop(); + + auto msecs = sw.peek().total!"msecs"; + writefln("Write: %s ms (%s kHz)", msecs, ITERATIONS / msecs); + } + + auto data = buf.getContents().dup; + + { + auto readBuf = tInputRangeTransport(data); + auto prot = tBinaryProtocol(readBuf); + auto ooe = OneOfEach(); + + auto sw = StopWatch(AutoStart.yes); + foreach (i; 0 .. ITERATIONS) { + readBuf.reset(data); + ooe.read(prot); + } + sw.stop(); + + auto msecs = sw.peek().total!"msecs"; + writefln(" Read: %s ms (%s kHz)", msecs, ITERATIONS / msecs); + } +} |