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 30, 2016
1 parent a8de4ee commit 9378783
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ install:
- sh autogen.sh

before_script:
- sudo apt-get -qq --force-yes install valgrind
- # note: valgrind is only available on Linux
- if [ "$CC" == "gcc" ] && [ "$TRAVIS_OS_NAME" == "linux" ]; then export ENA_VG="--enable-valgrind"; fi
- if [ "$CC" == "clang" ] && [ "$TRAVIS_OS_NAME" == "linux" ]; then export SANITIZER="-fsanitize=address" ; fi
Expand All @@ -38,6 +39,8 @@ before_script:
script:
- if [ "$CC" == "clang" ] && [ "$TRAVIS_OS_NAME" == "linux" ]; then scan-build-3.6 --status-bugs make check TESTS="" && make clean ; fi
- make
- valgrind --tool=callgrind ls
- export VERBOSE=1
- make check
- cat tests/perf_to_string.trs
- make distcheck
9 changes: 8 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 Expand Up @@ -60,6 +61,12 @@ check_PROGRAMS += test_object_object_add_exFormatted
test_object_object_add_exFormatted_SOURCES = test_object_object_add_ex.c parse_flags.c parse_flags.h
test_object_object_add_exFormatted_CPPFLAGS = -DTEST_FORMATTED

# performancebaseline tests
# TODO: guard via configure switch! -- rgerhards, 2016-11-29
TESTS += perf_to_string.test



EXTRA_DIST=
EXTRA_DIST += $(TESTS)
EXTRA_DIST += test-defs.sh
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;
}
32 changes: 32 additions & 0 deletions tests/perf_to_string.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/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
export RETCODE=$?
echo return code $RETCODE
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

0 comments on commit 9378783

Please sign in to comment.