From 7980cf0f80d29f2af52ab7f2db4f8f6f2d33afe8 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Wed, 19 Jul 2017 23:26:39 +0200 Subject: [PATCH] Add bench for libcollection. --- bench/Makefile | 8 ++++++ bench/bench-libcollection.c | 57 +++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 bench/bench-libcollection.c diff --git a/bench/Makefile b/bench/Makefile index f48c6994..f7945d51 100644 --- a/bench/Makefile +++ b/bench/Makefile @@ -98,6 +98,14 @@ bench-sparsepp0: @./bench-sparsepp.exe 42 @./bench-sparsepp.exe 43 +# LIBCOLLECTION shall point to the directory where the 'src' directory is. +bench-libcollection: + if test -n "$${LIBCOLLECTION}" ; then make bench-libcollection0 ; else echo "Nothing to be done." ; fi + +bench-libcollection0: + $(CC) $(CFLAGS) $(CPPFLAGS) -I "$${LIBCOLLECTION}/include" -L "$${LIBCOLLECTION}" -static bench-libcollection.c -lcollectc -o bench-libcollection.exe + @./bench-libcollection.exe 20 + bench-plain: $(CC) $(CFLAGS) $(CPPFLAGS) bench-plain-c.c -o bench-plain-c.exe @./bench-plain-c.exe diff --git a/bench/bench-libcollection.c b/bench/bench-libcollection.c new file mode 100644 index 00000000..f50774ae --- /dev/null +++ b/bench/bench-libcollection.c @@ -0,0 +1,57 @@ +#define NDEBUG + +#include +#include +#include +#include +#include +#include + +#include "array.h" + +#include "common.h" + +/********************************************************************************************/ + +static void test_array(size_t n) +{ + Array *a1, *a2; + enum cc_stat stat; + + stat = array_new(&a1); + if (stat != CC_OK) abort(); + stat = array_new(&a2); + if (stat != CC_OK) abort(); + + for(size_t i = 0; i < n; i++) { + stat = array_add(a1, (void*) (uintptr_t)rand_get() ); + if (stat != CC_OK) abort(); + stat = array_add(a2, (void*) (uintptr_t)rand_get() ); + if (stat != CC_OK) abort(); + } + unsigned int s = 0; + for(unsigned long i = 0; i < n; i++) { + void *e, *f; + stat = array_get_at(a1, i, &e); + if (stat != CC_OK) abort(); + stat = array_get_at(a2, i, &f); + if (stat != CC_OK) abort(); + s += ((unsigned int)(uintptr_t) e) * ((unsigned int)(uintptr_t) f); + } + g_result = s; + + array_destroy(a1); + array_destroy(a2); +} + + +/********************************************************************************************/ + +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); + exit(0); +} +