diff --git a/.gitignore b/.gitignore index 4c7cf96..754a28f 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ test/testMatch test/testParser test/testRender test/testPsyc +test/testPsycFast test/testText test/isRoutingVar test/getVarType diff --git a/bench/Makefile b/bench/Makefile index 1acfe12..2aa0ca3 100644 --- a/bench/Makefile +++ b/bench/Makefile @@ -8,6 +8,8 @@ INIT = (setq load-path (cons \"/usr/share/emacs/site-lisp/org-mode\" load-path) org-src-preserve-indentation t) \ (require 'org-install) +ORG = benchmark.org results.org + wiki2org: perl -pe '\ s/^= (.*) =\s*$$/#+TITLE: $$1\n/; \ @@ -17,18 +19,21 @@ wiki2org: s/^}}}/#+END_SRC/ \ ' benchmark.wiki >benchmark.org -tangle: +packets: emacs -Q --batch --eval \ "(progn ${INIT} (find-file \"benchmark.org\") \ (org-babel-tangle) (kill-buffer))" perl -pi -e 'print "\n" unless $$p; $$p=1' packets/user_profile.psyc html: - emacs -Q --batch --eval \ - "(progn ${INIT} (find-file \"benchmark.org\") \ - (org-export-as-html-batch) (kill-buffer))" + for f in ${ORG}; do \ + emacs -Q --batch --eval \ + "(progn ${INIT} (find-file \"$$f\") \ + (org-export-as-html-batch) (kill-buffer))"; \ + done pdf: - emacs -Q --batch --eval \ - "(progn ${INIT} (find-file \"benchmark.org\") \ - (org-export-as-pdf org-export-headline-levels) (kill-buffer))" + for f in ${ORG}; do \ + emacs -Q --batch --eval \ + "(progn ${INIT} (find-file \"$@.org\") \ + (org-export-as-pdf org-export-headline-levels) (kill-buffer))" diff --git a/bench/results.org b/bench/results.org index 2352788..e46d1f6 100644 --- a/bench/results.org +++ b/bench/results.org @@ -5,20 +5,22 @@ Parsing time of 1 000 000 packets in milliseconds: -| | libpsyc | json-c | json-glib | libxml sax | libxml | rapidxml fast | rapidxml | -|-----------+---------+--------+-----------+------------+--------+---------------+----------| -| presence | 597 | 3247 | 10197 | 4997 | 7557 | 1643 | 1719 | -| chat msg | 714 | | | 5997 | 9777 | 1799 | 1893 | -| activity | 903 | 5768 | 16846 | 13357 | 28858 | 4001 | 4419 | -| user prof | 1806 | 5847 | 17468 | 7350 | 12377 | 2218 | 2477 | -| / | <> | < | > | < | > | < | > | - +| | libpsyc | libpsyc fast | json-c | json-glib | libxml sax | libxml | rapidxml fast | rapidxml | +|-----------+---------+--------------+--------+-----------+------------+--------+---------------+----------| +| presence | 597 | 246 | 3247 | 10197 | 4997 | 7557 | 1643 | 1719 | +| chat msg | 714 | 320 | | | 5997 | 9777 | 1799 | 1893 | +| activity | 903 | 366 | 5768 | 16846 | 13357 | 28858 | 4001 | 4419 | +| user prof | 1806 | 608 | 5847 | 17468 | 7350 | 12377 | 2218 | 2477 | +|-----------+---------+--------------+--------+-----------+------------+--------+---------------+----------| +| / | < | > | < | > | < | > | < | > | * Commands used : ./testPsyc -snc 1000000 -f $file +: ./testPsycFast -sc 1000000 -f $file : ./testJson -snc 1000000 -f $file : ./testJsonGlib -snc 1000000 -f $file +: ./testStrlen -sc 1000000 -f $file : ./rapidxml 1000000 $file : fast_mode=1 ./rapidxml 1000000 $file : ./libxml 1000000 $file diff --git a/test/Makefile b/test/Makefile index c01a811..4d3c38e 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,9 +1,10 @@ OPT = -O2 DEBUG = 2 -CFLAGS = -I../include -I../src -Wall -std=c99 ${OPT} +CFLAGS_COMMON = -Wall -std=c99 ${OPT} +CFLAGS = -I../include -I../src ${CFLAGS_COMMON} LDFLAGS = -L../lib LOADLIBES = -lpsyc -lm -TARGETS = testPsyc testParser testMatch testRender testText isRoutingVar getVarType +TARGETS = testPsyc testPsycFast testParser testMatch testRender testText isRoutingVar getVarType O = test.o WRAPPER = DIET = diet @@ -20,7 +21,8 @@ all: ${TARGETS} it: all testPsyc: LOADLIBES := ${LOADLIBES} ${LOADLIBES_NET} -testPsyc: test.o +testPsycFast: LOADLIBES := ${LOADLIBES} ${LOADLIBES_NET} +#testPsycFast: LOADLIBES := ${LOADLIBES_NET} diet: WRAPPER = ${DIET} diet: all diff --git a/test/test.c b/test/test.c index ef09db4..b11f683 100644 --- a/test/test.c +++ b/test/test.c @@ -5,6 +5,10 @@ * "The C source code presented in this document is hereby granted to the public domain, and is completely free of any license restriction." */ +#ifndef __USE_POSIX +# define __USE_POSIX +#endif + #include #include #include @@ -18,7 +22,6 @@ #include #include -#define __USE_POSIX #include #include "test.h" diff --git a/test/test.h b/test/test.h index b49f7f8..8b7b0be 100644 --- a/test/test.h +++ b/test/test.h @@ -1,10 +1,18 @@ #ifndef TEST_H # define TEST_H +#ifndef RECV_BUF_SIZE # define RECV_BUF_SIZE 8 * 1024 +#endif +#ifndef CONT_BUF_SIZE # define CONT_BUF_SIZE 8 * 1024 +#endif +#ifndef SEND_BUF_SIZE # define SEND_BUF_SIZE 8 * 1024 +#endif +#ifndef NUM_PARSERS # define NUM_PARSERS 100 +#endif void test_init(int i); int test_input(int i, char *recvbuf, size_t nbytes); diff --git a/test/testPsyc.c b/test/testPsyc.c index ce397ef..f3cbf0f 100644 --- a/test/testPsyc.c +++ b/test/testPsyc.c @@ -12,7 +12,7 @@ #include #include -#include "test.h" +#include "test.c" // max size for routing & entity header #define ROUTING_LINES 16 @@ -31,8 +31,9 @@ psycModifier entity[NUM_PARSERS][ENTITY_LINES]; int contbytes, exit_code; -static inline void resetString (psycString *s, uint8_t freeptr); -t +static inline +void resetString (psycString *s, uint8_t freeptr); + // initialize parser & packet variables void test_init (int i) { // reset parser state & packet @@ -301,8 +302,7 @@ int test_input (int i, char *recvbuf, size_t nbytes) { return ret; } -static inline -void resetString (psycString *s, uint8_t freeptr) +inline void resetString (psycString *s, uint8_t freeptr) { if (freeptr && s->length) free((void*)s->ptr); diff --git a/test/testPsycFast.c b/test/testPsycFast.c new file mode 100644 index 0000000..0e1aa28 --- /dev/null +++ b/test/testPsycFast.c @@ -0,0 +1,88 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +//#define PSYC_PARSE_INLINE +//#include "../src/parse.c" +#include + +#include "test.c" + +// max size for routing & entity header +#define ROUTING_LINES 16 +#define ENTITY_LINES 32 + +// cmd line args +char *filename, *port = "4440"; +uint8_t verbose, stats; +uint8_t routing_only; +size_t count = 1, recv_buf_size = RECV_BUF_SIZE; + +psycParseState parser; + +void test_init (int i) { + // reset parser state + if (routing_only) + psyc_initParseState2(&parser, PSYC_PARSE_ROUTING_ONLY); + else + psyc_initParseState(&parser); +} + +int test_input (int i, char *recvbuf, size_t nbytes) { + char oper; + psycString name, value; + int ret; + + parser.buffer = (psycString){nbytes, recvbuf}; + parser.cursor = 0; + + for (;;) { + ret = psyc_parse(&parser, &oper, &name, &value); + + if (ret == PSYC_PARSE_COMPLETE || ret < 0) + return -1; + } +} + +int main (int argc, char **argv) { + int c; + while ((c = getopt (argc, argv, "f:p:b:c:qrsvh")) != -1) { + switch (c) { + case 'f': filename = optarg; break; + case 'p': port = optarg; check_range(c, optarg, 1, 0); break; + case 'b': recv_buf_size = atoi(optarg); check_range(c, optarg, 1, RECV_BUF_SIZE); break; + case 'c': count = atoi(optarg); check_range(c, optarg, 1, 0); break; + case 'r': routing_only = 1; break; + case 's': stats = 1; break; + case 'v': verbose++; break; + case 'h': + printf( + "testPsyc -f [-b ] [-c ] [-mnqrSsvP]\n" + "testPsyc [-p ] [-b ] [-nqrsvP]\n" + " -f \tInput file name\n" + " -p \t\tListen on TCP port, default is %s\n" + " -b \tRead/receive buffer size, default is %d\n" + " -c \t\tParse data from file times\n" + " -r\t\t\tParse routing header only\n" + " -s\t\t\tShow statistics at the end\n" + " -h\t\t\tShow this help\n" + " -v\t\t\tVerbose\n", + port, RECV_BUF_SIZE); + exit(0); + case '?': exit(-1); + default: abort(); + } + } + + if (filename) + test_file(filename, count, recv_buf_size); + else + test_server(port, count, recv_buf_size); + + return 0; +}