forked from rsyslog/libfastjson
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
testbench: add performance-testing tools
closes rsyslog#129
- Loading branch information
Showing
4 changed files
with
91 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/bin/sh | ||
# Common definitions | ||
#if test -z "$srcdir"; then | ||
#srcdir="${0%/*}" | ||
#test "$srcdir" = "$0" && srcdir=. | ||
#test -z "$srcdir" && srcdir=. | ||
#fi | ||
#. "$srcdir/test-defs.sh" | ||
|
||
# first, get baseline from system-installed library | ||
rm -f callgrind.out &> /dev/null | ||
valgrind --tool=callgrind --callgrind-out-file=callgrind.out .libs/perf_to_string | ||
MAXCYCLES=$(grep < callgrind.out "^totals:" | tr -dc '0-9') | ||
echo "system installed libfastjson requires $MAXCYCLES cycles" | ||
# give 5% allowence to care for exec env differences between runs | ||
MAXCYCLES=$((MAXCYCLES * 105)) | ||
MAXCYCLES=$((MAXCYCLES / 100)) | ||
|
||
ls -l ../.libs/libfastjson.so | ||
rm -f callgrind.out &> /dev/null | ||
LD_PRELOAD="../.libs/libfastjson.so.4" valgrind --tool=callgrind --callgrind-out-file=callgrind.out .libs/perf_to_string | ||
CYCLES=$(grep < callgrind.out "^totals:" | tr -dc '0-9') | ||
echo "libfastjson being testes requires $CYCLES cycles" | ||
|
||
if [ $CYCLES -gt $MAXCYCLES ]; then | ||
echo | ||
echo performance issue: we need $CYCLES cycles, but upper bound is $MAXCYCLES | ||
exit 1 | ||
fi | ||
rm callgrind.out |