Skip to content

Commit

Permalink
testbench: add performance-testing tools
Browse files Browse the repository at this point in the history
  • Loading branch information
rgerhards committed Nov 29, 2016
1 parent a8de4ee commit 31b9870
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
51 changes: 51 additions & 0 deletions tests/perf_to_string.c
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
*
* 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 <stdio.h>
#include <stdlib.h>
#include <string.h>

#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;
}

0 comments on commit 31b9870

Please sign in to comment.