diff --git a/tests/Makefile.am b/tests/Makefile.am index 9dca5da..bcec80e 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -32,7 +32,8 @@ check_PROGRAMS += $(TESTS:.test=) # some programs that do internal checking check_PROGRAMS += chk_version \ - cr_obj_multi + cr_obj_multi \ + perf_to_string TESTS += chk_version diff --git a/tests/perf_to_string.c b/tests/perf_to_string.c new file mode 100644 index 0000000..5e05a43 --- /dev/null +++ b/tests/perf_to_string.c @@ -0,0 +1,51 @@ +/* libfastjson testbench tool + * This program can be used to test the performance of the _to_string() + * subsystem. It is meant to be used together with a profiler. + * + * Copyright (c) 2016 Adiscon GmbH + * Rainer Gerhards + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the MIT license. See COPYING for details. + * + */ +#include "config.h" + +#include "../json.h" + +#include +#include +#include + +#define NUM_ITERATIONS 100000 + +int +main(int __attribute__((unused)) argc, char __attribute__((unused)) **argv) +{ + int i; + struct fjson_object *json; + + json = fjson_object_new_object(); + fjson_object_object_add(json, "string1", fjson_object_new_string("This is a test")); + fjson_object_object_add(json, "string2", fjson_object_new_string("This is a " + "loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo" + "ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo" + "ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong" + "test")); + fjson_object_object_add(json, "string3", fjson_object_new_string("This is\n a test öäü")); + fjson_object_object_add(json, "int1", fjson_object_new_int(4711)); + + + for(i = 0 ; i < NUM_ITERATIONS ; ++i) { + const char *dummy = fjson_object_to_json_string(json); + if(dummy == NULL) { + fprintf(stderr, "dummy has received no output!"); + exit(1); + } + if(i == 0) + printf("%s\n", dummy); + } + + fjson_object_put(json); + return 0; +}