Add new bench for m*lib buffer.

This commit is contained in:
Patrick Pelissier committed 2017-07-18 19:26:54 +02:00
1 parent 749cd43306
commit 9309bb64d5
2 files changed
+65 -2

No files matched your search

+4 -2
View File
@@ -9,7 +9,7 @@ all: benchmark bench-plain
benchmark: bench-mlib bench-mlib-mempool bench-stl bench-klib bench-qt bench-glib bench-libdynamic bench-sparsepp
bench-mlib:
$(CC) $(CFLAGS) $(CPPFLAGS) bench-mlib.c -o bench-mlib.exe
$(CC) $(CFLAGS) $(CPPFLAGS) -pthread bench-mlib.c -o bench-mlib.exe
@./bench-mlib.exe 10
@./bench-mlib.exe 20
@./bench-mlib.exe 30
@@ -18,9 +18,10 @@ bench-mlib:
@./bench-mlib.exe 42
@./bench-mlib.exe 43
@./bench-mlib.exe 50
@./bench-mlib.exe 60
bench-mlib-mempool:
$(CC) $(CFLAGS) $(CPPFLAGS) bench-mlib.c -DUSE_MEMPOOL -o bench-mlib-mempool.exe
$(CC) $(CFLAGS) $(CPPFLAGS) bench-mlib.c -DUSE_MEMPOOL -pthread -o bench-mlib-mempool.exe
@./bench-mlib-mempool.exe 10
@./bench-mlib-mempool.exe 20
@./bench-mlib-mempool.exe 30
@@ -29,6 +30,7 @@ bench-mlib-mempool:
@./bench-mlib-mempool.exe 42
@./bench-mlib-mempool.exe 43
@./bench-mlib-mempool.exe 50
@./bench-mlib-mempool.exe 60
bench-stl:
$(CXX) $(CFLAGS) $(CPPFLAGS) bench-stl.cpp -o bench-stl.exe
+61
View File
@@ -14,6 +14,8 @@
#include "m-algo.h"
#include "m-mempool.h"
#include "m-string.h"
#include "m-buffer.h"
#include "m-mutex.h"
#include "common.h"
@@ -261,6 +263,63 @@ static void test_sort(size_t n)
}
}
/********************************************************************************************/
//NOTE: not sure this test is representative.
BUFFER_DEF(uint, unsigned int, 0, BUFFER_QUEUE|BUFFER_BLOCKING)
buffer_uint_t g_buff;
static void conso(void *arg)
{
unsigned int j;
size_t *p_n = arg;
size_t n = *p_n;
for(int i = 0; i < n;i++) {
buffer_uint_pop(&j, g_buff);
if (j >= n) abort();
}
}
static void prod(void *arg)
{
size_t *p_n = arg;
size_t n = *p_n;
for(unsigned int i = 0; i < n;i++) {
buffer_uint_push(g_buff, i);
}
}
static void test_buffer(size_t n)
{
const int cpu_count = get_cpu_count();
const int prod_count = cpu_count/2;
const int conso_count = cpu_count - prod_count;
if (cpu_count < 2) {
fprintf(stderr, "WARNING: Can not measure Buffer performance.\n");
return;
}
m_thread_t idx_p[prod_count];
m_thread_t idx_c[conso_count];
buffer_uint_init(g_buff, 64*cpu_count);
for(int i = 0; i < prod_count; i++) {
m_thread_create (idx_p[i], prod, &n);
}
for(int i = 0; i < conso_count; i++) {
m_thread_create (idx_c[i], conso, &n);
}
for(int i = 0; i < prod_count; i++) {
m_thread_join(idx_p[i]);
}
for(int i = 0; i < conso_count; i++) {
m_thread_join(idx_c[i]);
}
buffer_uint_clear(g_buff);
}
/********************************************************************************************/
int main(int argc, const char *argv[])
@@ -282,6 +341,8 @@ int main(int argc, const char *argv[])
test_function("DictS time", 1000000, test_dict_str);
if (n == 50)
test_function("Sort time", 10000000, test_sort);
if (n == 60)
test_function("Buffer time", 1000000, test_buffer);
exit(0);
}