From f1b87207cd338de87fa5538f02ec0166add240ef Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Wed, 16 Aug 2017 20:38:25 +0200 Subject: [PATCH] Add bench libsrt --- bench/Makefile | 14 +++++++++ bench/bench-libsrt.c | 72 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 bench/bench-libsrt.c diff --git a/bench/Makefile b/bench/Makefile index cb3259ba..384ea6b6 100644 --- a/bench/Makefile +++ b/bench/Makefile @@ -179,6 +179,20 @@ bench-qlibc0: @LD_LIBRARY_PATH="$${QLIBC}/lib:$${LD_LIBRARY_PATH}" ./bench-qlibc.exe 42 @LD_LIBRARY_PATH="$${QLIBC}/lib:$${LD_LIBRARY_PATH}" ./bench-qlibc.exe 41 +# LIBSRT shall point to the directory where the source are +bench-libsrt: + if test -n "$${LIBSRT}" ; then make bench-libsrt0 ; else echo "Nothing to be done." ; fi + +bench-libsrt0: + $(CC) $(CFLAGS) $(CPPFLAGS) -I "$${LIBSRT}/src" bench-libsrt.c -o bench-libsrt.exe $${LIBSRT}/libsrt.a + @./bench-libsrt.exe 10 + @./bench-libsrt.exe 20 + @./bench-libsrt.exe 41 + @./bench-libsrt.exe 42 + @./bench-libsrt.exe 43 + @./bench-libsrt.exe 50 + + ############################################################################ bench-plain: diff --git a/bench/bench-libsrt.c b/bench/bench-libsrt.c new file mode 100644 index 00000000..2aea2098 --- /dev/null +++ b/bench/bench-libsrt.c @@ -0,0 +1,72 @@ +#define NDEBUG + +#include +#include +#include + +#include "svector.h" +#include "smap.h" +#include "smset.h" + +#include "common.h" + +/********************************************************************************************/ + +static void test_array(size_t n) +{ + sv_t *a1 = sv_alloc ( sizeof (unsigned int), 16, NULL); + sv_t *a2 = sv_alloc ( sizeof (unsigned int), 16, NULL); + + for(size_t i = 0; i < n; i++) { + unsigned int value = rand_get(); + sv_push(&a1, &value ); + value = rand_get(); + sv_push(&a2, &value ); + } + unsigned int s = 0; + for(unsigned long i = 0; i < n; i++) { + s += *(unsigned int*)sv_at(a1, i ) * *(unsigned int *)sv_at(a2, i ); + } + g_result = s; + + sv_free(&a1); + sv_free(&a2); +} + +/********************************************************************************************/ + +/* There is no 'unsigned long' key in smset */ + +/********************************************************************************************/ + +static int cmp_float (const void *a, const void *b) +{ + const float *pa=a; + const float *pb = b; + return (*pa < *pb) ? -1 : *pa > *pb; +} + +static void test_sort(size_t n) +{ + sv_t *a1 = sv_alloc(sizeof(float), 16, cmp_float); + for(size_t i = 0; i < n; i++) { + unsigned int value = rand_get(); + sv_push(&a1, &value ); + } + sv_sort(a1); + g_result = *(float*)sv_at(a1, 0); + sv_free(&a1); +} + +/********************************************************************************************/ + +int main(int argc, const char *argv[]) +{ + int n = (argc > 1) ? atoi(argv[1]) : 0; + if (n == 20) + test_function("Array time", 100000000, test_array); + if (n == 50) + test_function("Sort time", 10000000, test_sort); + exit(0); +} +