From 3e08a81abfe39c0881b5017a52a4f54c0fa79a7f Mon Sep 17 00:00:00 2001 From: "tg(x)" <*@tg-x.net> Date: Tue, 24 May 2011 17:37:00 +0200 Subject: [PATCH] bench: binary packet generation & results --- bench/.gitignore | 1 + bench/Makefile | 2 +- bench/benchmark.org | 47 ++++++++++++++------ bench/packets/binary/json-footer | 1 + bench/packets/binary/json-header | 1 + bench/packets/binary/psyc-content | 2 + bench/packets/binary/psyc-header | 0 bench/packets/binary/xml-footer | 1 + bench/packets/binary/xml-header | 1 + test/Makefile | 74 ++++++++++++++++++++++++------- test/testJsonGlib.c | 5 +-- 11 files changed, 100 insertions(+), 35 deletions(-) create mode 100644 bench/packets/binary/json-footer create mode 100644 bench/packets/binary/json-header create mode 100644 bench/packets/binary/psyc-content create mode 100644 bench/packets/binary/psyc-header create mode 100644 bench/packets/binary/xml-footer create mode 100644 bench/packets/binary/xml-header diff --git a/bench/.gitignore b/bench/.gitignore index bffe52f..fd2f6c3 100644 --- a/bench/.gitignore +++ b/bench/.gitignore @@ -1,3 +1,4 @@ *.html *.pdf results/ +packets/binary/[0-9]* diff --git a/bench/Makefile b/bench/Makefile index e263ac0..cecdfe3 100644 --- a/bench/Makefile +++ b/bench/Makefile @@ -7,7 +7,7 @@ INIT = (setq load-path (cons \"/usr/share/emacs/site-lisp/org-mode\" load-path) org-babel-tangle-pad-newline nil \ org-src-preserve-indentation t) \ (require 'org-install) - +#' ORG = benchmark.org html: diff --git a/bench/benchmark.org b/bench/benchmark.org index 3bcce3b..0916eaa 100644 --- a/bench/benchmark.org +++ b/bench/benchmark.org @@ -129,23 +129,42 @@ We'll use the latter here: Parsing time of 1 000 000 packets, in milliseconds. a simple strlen scan of the respective message is provided for comparison. -| input: | PSYC | | JSON | | | XML | | -| parser: | strlen | libpsyc | json-c | json-glib | libxml sax | libxml | rapidxml | -|-----------+--------+---------+--------+-----------+------------+--------+----------| -| user prof | 55 | 608 | 4715 | 17468 | 7350 | 12377 | 2477 | -|-----------+--------+---------+--------+-----------+------------+--------+----------| -| / | < | > | < | > | < | | > | +| input: | PSYC | | JSON | | | XML | | +| parser: | strlen | libpsyc | json-c | json-glib | libxml sax | libxml | rapidxml | +|--------------+--------+---------+--------+-----------+------------+--------+----------| +| user profile | 55 | 608 | 4715 | 16503 | 7350 | 12377 | 2477 | +|--------------+--------+---------+--------+-----------+------------+--------+----------| +| / | < | > | < | > | < | | > | Pure syntax comparisons above, protocol performance comparisons below: -| input: | PSYC | | JSON | | | XMPP | | -| parser: | strlen | libpsyc | json-c | json-glib | libxml sax | libxml | rapidxml | -|-----------+--------+---------+--------+-----------+------------+--------+----------| -| presence | 30 | 246 | 2463 | 10197 | 4997 | 7557 | 1719 | -| chat msg | 41 | 320 | | | 5997 | 9777 | 1893 | -| activity | 42 | 366 | 4666 | 16846 | 13357 | 28858 | 4419 | -|-----------+--------+---------+--------+-----------+------------+--------+----------| -| / | < | > | < | > | < | | > | +| input: | PSYC | | JSON | | | XMPP | | +| parser: | strlen | libpsyc | json-c | json-glib | libxml sax | libxml | rapidxml | +|-----------------+--------+---------+--------+-----------+------------+--------+----------| +| presence | 30 | 236 | 2463 | 10016 | 4997 | 7557 | 1719 | +| chat msg | 40 | 295 | 2147 | 9526 | 5997 | 9777 | 1893 | +| activity | 42 | 353 | 4666 | 16327 | 13357 | 28858 | 4356 | +| psyc-unfriendly | 70 | 286 | 2892 | 12567 | 5538 | 8659 | 1896 | +| json-unfriendly | 49 | 430 | 2328 | 10006 | 5141 | 7875 | 1751 | +| xml-unfriendly | 37 | 296 | 2156 | 9591 | 5571 | 8769 | 1765 | +|-----------------+--------+---------+--------+-----------+------------+--------+----------| +| / | < | > | < | > | < | | > | + +Parsing large amounts of binary data. For JSON & XML base64 encoding was used. +Note that the results below include only the parsing time, base64 decoding was +not performed. + +| input: | PSYC | | JSON | | | XML | | +| parser: | strlen | libpsyc | json-c | json-glib | libxml sax | libxml | rapidxml | +|-------------+--------+---------+--------+------------+------------+-----------+----------| +| binary 7K | 92 | 77 | 14459 | 98000 | 11445 | 19299 | 8701 | +| binary 70K | 53 | 77 | 14509 | 1003900 | 96209 | 167738 | 74296 | +| binary 700K | 42 | 77 | 14551 | 10616000 | 842025 | 1909428 | 729419 | +| binary 7M | 258 | 78 | 14555 | 120810000 | 12466610 | 16751363 | 7581169 | +| binary 70M | 304 | 80 | 14534 | 1241000000 | 169622110 | 296017820 | 75308906 | +|-------------+--------+---------+--------+------------+------------+-----------+----------| +| / | < | > | < | > | < | | > | + These tests were performed on a 2.53 GHz Intel(R) Core(TM)2 Duo P9500 CPU. diff --git a/bench/packets/binary/json-footer b/bench/packets/binary/json-footer new file mode 100644 index 0000000..6b822c2 --- /dev/null +++ b/bench/packets/binary/json-footer @@ -0,0 +1 @@ +"} \ No newline at end of file diff --git a/bench/packets/binary/json-header b/bench/packets/binary/json-header new file mode 100644 index 0000000..e045aed --- /dev/null +++ b/bench/packets/binary/json-header @@ -0,0 +1 @@ +{"data":" \ No newline at end of file diff --git a/bench/packets/binary/psyc-content b/bench/packets/binary/psyc-content new file mode 100644 index 0000000..7ab1318 --- /dev/null +++ b/bench/packets/binary/psyc-content @@ -0,0 +1,2 @@ +:_foo bar +_data diff --git a/bench/packets/binary/psyc-header b/bench/packets/binary/psyc-header new file mode 100644 index 0000000..e69de29 diff --git a/bench/packets/binary/xml-footer b/bench/packets/binary/xml-footer new file mode 100644 index 0000000..f09e8d4 --- /dev/null +++ b/bench/packets/binary/xml-footer @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/bench/packets/binary/xml-header b/bench/packets/binary/xml-header new file mode 100644 index 0000000..3f35021 --- /dev/null +++ b/bench/packets/binary/xml-header @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/Makefile b/test/Makefile index 66c2445..f7f49ea 100644 --- a/test/Makefile +++ b/test/Makefile @@ -50,23 +50,6 @@ test: ${TARGETS} x=0; for f in packets/[0-9]*; do echo ">> $$f"; ./testPsyc -f $$f | ${DIFF} -u $$f -; x=$$((x+$$?)); done; exit $$x x=0; for f in packets/[0-9]*; do echo ">> $$f"; ./testPsyc -rf $$f | ${DIFF} -u $$f -; x=$$((x+$$?)); done; exit $$x -bench: bench-psyc bench-json bench-xml - -bench-dir: - @mkdir -p ../bench/results - -bench-psyc: bench-dir testStrlen testPsycSpeed - for f in ../bench/packets/*.psyc; do bf=`basename $$f`; echo strlen: $$bf; ./testStrlen -sc 1000000 -f $$f | ${TEE} -a ../bench/results/$$bf.strlen; done - for f in ../bench/packets/*.psyc; do bf=`basename $$f`; echo libpsyc: $$f; ./testPsycSpeed -sc 1000000 -f $$f | ${TEE} -a ../bench/results/$$bf; done - -bench-json: bench-dir testStrlen testJson testJsonGlib - for f in ../bench/packets/*.json; do bf=`basename $$f`; echo strlen: $$bf; ./testStrlen -sc 1000000 -f $$f | ${TEE} -a ../bench/results/$$bf.strlen; done - for f in ../bench/packets/*.json; do bf=`basename $$f`; echo json-c: $$bf; ./testJson -snc 1000000 -f $$f | ${TEE} -a ../bench/results/$$bf; done - for f in ../bench/packets/*.json; do bf=`basename $$f`; echo json-glib: $$bf; ./testJsonGlib -snc 1000000 -f $$f | ${TEE} -a ../bench/results/$$bf-glib; done - -bench-xml: bench-dir testStrlen - for f in ../bench/packets/*.xml; do bf=`basename $$f`; echo strlen: $$bf; ./testStrlen -sc 1000000 -f $$f | ${TEE} -a ../bench/results/$$bf.strlen; done - .NOTPARALLEL: nettestrun nettest: nettestfull nettestsplit @@ -96,3 +79,60 @@ srvstart: srvkill: pkill -x testPsyc + + +bench: bench-genpkts bench-psyc bench-json bench-xml + +bench-dir: + @mkdir -p ../bench/results + +bench-psyc: bench-dir testStrlen testPsycSpeed + for f in ../bench/packets/*.psyc ../bench/packets/binary/*.psyc; do bf=`basename $$f`; echo strlen: $$bf; ./testStrlen -sc 1000000 -f $$f | ${TEE} -a ../bench/results/$$bf.strlen; done + for f in ../bench/packets/*.psyc ../bench/packets/binary/*.psyc; do bf=`basename $$f`; echo libpsyc: $$f; ./testPsycSpeed -sc 1000000 -f $$f | ${TEE} -a ../bench/results/$$bf; done + +bench-json: bench-dir testStrlen testJson testJsonGlib + for f in ../bench/packets/*.json ../bench/packets/binary/*.json; do bf=`basename $$f`; echo strlen: $$bf; ./testStrlen -sc 1000000 -f $$f | ${TEE} -a ../bench/results/$$bf.strlen; done + for f in ../bench/packets/*.json ../bench/packets/binary/*.json; do bf=`basename $$f`; echo json-c: $$bf; ./testJson -snc 1000000 -f $$f | ${TEE} -a ../bench/results/$$bf; done + for f in ../bench/packets/*.json; do bf=`basename $$f`; echo json-glib: $$bf; ./testJsonGlib -snc 1000000 -f $$f | ${TEE} -a ../bench/results/$$bf-glib; done + +bench-xml: bench-dir testStrlen + for f in ../bench/packets/*.xml ../bench/packets/binary/*.xml; do bf=`basename $$f`; echo strlen: $$bf; ./testStrlen -sc 1000000 -f $$f | ${TEE} -a ../bench/results/$$bf.strlen; done + +bench-genpkts: + @${MAKE} genpkt header=../bench/packets/binary/psyc-header content=../bench/packets/binary/psyc-content bs=7000 of=../bench/packets/binary/7K.psyc + @${MAKE} genpkt header=../bench/packets/binary/psyc-header content=../bench/packets/binary/psyc-content bs=70000 of=../bench/packets/binary/70K.psyc + @${MAKE} genpkt header=../bench/packets/binary/psyc-header content=../bench/packets/binary/psyc-content bs=700000 of=../bench/packets/binary/700K.psyc + @${MAKE} genpkt header=../bench/packets/binary/psyc-header content=../bench/packets/binary/psyc-content bs=7000000 of=../bench/packets/binary/7000K.psyc + @${MAKE} genpkt header=../bench/packets/binary/psyc-header content=../bench/packets/binary/psyc-content bs=7000000 count=10 of=../bench/packets/binary/70000K.psyc +# @${MAKE} genpkt header=../bench/packets/binary/psyc-header content=../bench/packets/binary/psyc-content bs=7000000 count=100 of=../bench/packets/binary/700000K.psyc + + @${MAKE} genb64 header=../bench/packets/binary/json-header footer=../bench/packets/binary/json-footer bs=7000 of=../bench/packets/binary/7K.json + @${MAKE} genb64 header=../bench/packets/binary/json-header footer=../bench/packets/binary/json-footer bs=70000 of=../bench/packets/binary/70K.json + @${MAKE} genb64 header=../bench/packets/binary/json-header footer=../bench/packets/binary/json-footer bs=700000 of=../bench/packets/binary/700K.json + @${MAKE} genb64 header=../bench/packets/binary/json-header footer=../bench/packets/binary/json-footer bs=7000000 of=../bench/packets/binary/7000K.json + @${MAKE} genb64 header=../bench/packets/binary/json-header footer=../bench/packets/binary/json-footer bs=7000000 count=10 of=../bench/packets/binary/70000K.json +# @${MAKE} genb64 header=../bench/packets/binary/json-header footer=../bench/packets/binary/json-footer bs=7000000 count=100 of=../bench/packets/binary/700000K.json + + @${MAKE} genb64 header=../bench/packets/binary/xml-header footer=../bench/packets/binary/xml-footer bs=7000 of=../bench/packets/binary/7K.xml + @${MAKE} genb64 header=../bench/packets/binary/xml-header footer=../bench/packets/binary/xml-footer bs=70000 of=../bench/packets/binary/70K.xml + @${MAKE} genb64 header=../bench/packets/binary/xml-header footer=../bench/packets/binary/xml-footer bs=700000 of=../bench/packets/binary/700K.xml + @${MAKE} genb64 header=../bench/packets/binary/xml-header footer=../bench/packets/binary/xml-footer bs=7000000 of=../bench/packets/binary/7000K.xml + @${MAKE} genb64 header=../bench/packets/binary/xml-header footer=../bench/packets/binary/xml-footer bs=7000000 count=10 of=../bench/packets/binary/70000K.xml +# @${MAKE} genb64 header=../bench/packets/binary/xml-header footer=../bench/packets/binary/xml-footer bs=7000000 count=100 of=../bench/packets/binary/700000K.xml + +bs = 1 +count = 1 +genpkt: + @[[ -n "${of}" ]] + [[ -f "${of}" ]] || ( \ + cat ${header} >${of}; \ + perl -le 'my @se=stat(q('${content}')); print $$se[7] + ${bs} * ${count} + 1' >>${of}; \ + cat ${content} >>${of}; \ + dd if=/dev/urandom of=${of} bs=${bs} count=${count} oflag=append conv=notrunc; \ + echo -ne "\n|\n" >>${of} ) + +bs = 1 +count = 1 +genb64: + @[[ -n "${of}" ]] + [[ -f "${of}" ]] || (cat ${header} >${of}; dd if=/dev/urandom bs=${bs} count=${count} | base64 -w0 >>${of}; cat ${footer} >>${of}) diff --git a/test/testJsonGlib.c b/test/testJsonGlib.c index 91fe9b5..2ef2e3e 100644 --- a/test/testJsonGlib.c +++ b/test/testJsonGlib.c @@ -32,7 +32,7 @@ void test_init (int i) { int test_input (int i, char *recvbuf, size_t nbytes) { JsonNode *root; - GError *error; + GError *error = NULL; char *str; size_t len; int r, ret; @@ -41,8 +41,7 @@ int test_input (int i, char *recvbuf, size_t nbytes) { if (!ret) { printf("Parse error\n"); - exit_code = 1; - return -1; + exit(1); } root = json_parser_get_root(parser);