Add bench of boost / locked free queue
This commit is contained in:
1 parent
95dba68fe1
commit
faf1fc56d0
2 files changed
+106
No files matched your search
@@ -192,6 +192,7 @@ bench-libsrt0:
|
|||||||
@./bench-libsrt.exe 43
|
@./bench-libsrt.exe 43
|
||||||
@./bench-libsrt.exe 50
|
@./bench-libsrt.exe 50
|
||||||
|
|
||||||
|
|
||||||
# LIBLFDS shall point to the directory where the bin/build/inc/obj/src directories are
|
# LIBLFDS shall point to the directory where the bin/build/inc/obj/src directories are
|
||||||
# The library shall be built.
|
# The library shall be built.
|
||||||
bench-liblfds:
|
bench-liblfds:
|
||||||
@@ -201,6 +202,7 @@ bench-liblfds0:
|
|||||||
$(CC) $(CFLAGS) $(CPPFLAGS) -I "$${LIBLFDS}/inc" bench-liblfds.c -o bench-liblfds.exe $${LIBLFDS}/bin/liblfds711.so -lpthread
|
$(CC) $(CFLAGS) $(CPPFLAGS) -I "$${LIBLFDS}/inc" bench-liblfds.c -o bench-liblfds.exe $${LIBLFDS}/bin/liblfds711.so -lpthread
|
||||||
@LD_LIBRARY_PATH="$${LIBLFDS}/bin:$${LD_LIBRARY_PATH}" ./bench-liblfds.exe 60
|
@LD_LIBRARY_PATH="$${LIBLFDS}/bin:$${LD_LIBRARY_PATH}" ./bench-liblfds.exe 60
|
||||||
|
|
||||||
|
|
||||||
# CONCURRENTQUEUE shall point to the directory where the bin/build/inc/obj/src directories are
|
# CONCURRENTQUEUE shall point to the directory where the bin/build/inc/obj/src directories are
|
||||||
# The library shall be built.
|
# The library shall be built.
|
||||||
bench-concurrentqueue:
|
bench-concurrentqueue:
|
||||||
@@ -210,6 +212,12 @@ bench-concurrentqueue0:
|
|||||||
$(CXX) $(CFLAGS) $(CPPFLAGS) -I "$${CONCURRENTQUEUE}/" bench-concurrentqueue.cpp -o bench-concurrentqueue.exe -lpthread
|
$(CXX) $(CFLAGS) $(CPPFLAGS) -I "$${CONCURRENTQUEUE}/" bench-concurrentqueue.cpp -o bench-concurrentqueue.exe -lpthread
|
||||||
@./bench-concurrentqueue.exe 60
|
@./bench-concurrentqueue.exe 60
|
||||||
|
|
||||||
|
|
||||||
|
# BOOST is assumed to be installed in the system
|
||||||
|
bench-boost:
|
||||||
|
$(CXX) $(CFLAGS) $(CPPFLAGS) bench-boost.cpp -o bench-boost.exe -lpthread
|
||||||
|
@./bench-boost.exe 60
|
||||||
|
|
||||||
############################################################################
|
############################################################################
|
||||||
|
|
||||||
bench-plain:
|
bench-plain:
|
||||||
|
|||||||
@@ -0,0 +1,98 @@
|
|||||||
|
#define NDEBUG
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include <boost/lockfree/queue.hpp>
|
||||||
|
|
||||||
|
#include "m-mutex.h"
|
||||||
|
#define MULTI_THREAD_MEASURE
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
|
|
||||||
|
/********************************************************************************************/
|
||||||
|
boost::lockfree::queue<unsigned int, boost::lockfree::capacity<4*64>> g_buff;
|
||||||
|
boost::lockfree::queue<unsigned long long, boost::lockfree::capacity<4*64>> g_final;
|
||||||
|
|
||||||
|
static void final(void *arg)
|
||||||
|
{
|
||||||
|
size_t *p_n = (size_t*) arg;
|
||||||
|
size_t n = *p_n;
|
||||||
|
unsigned long long j, s = 0;
|
||||||
|
for(unsigned int i = 0; i < n;i++) {
|
||||||
|
while (!g_final.pop(j));
|
||||||
|
s += j;
|
||||||
|
}
|
||||||
|
g_result = s;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void conso(void *arg)
|
||||||
|
{
|
||||||
|
unsigned int j;
|
||||||
|
size_t *p_n = (size_t*)arg;
|
||||||
|
size_t n = *p_n;
|
||||||
|
unsigned long long s = 0;
|
||||||
|
for(unsigned int i = 0; i < n;i++) {
|
||||||
|
while (!g_buff.pop(j));
|
||||||
|
s += j;
|
||||||
|
}
|
||||||
|
while (!g_final.push(s));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void prod(void *arg)
|
||||||
|
{
|
||||||
|
size_t *p_n = (size_t*)arg;
|
||||||
|
size_t n = *p_n;
|
||||||
|
size_t r = n;
|
||||||
|
for(unsigned int i = 0; i < n;i++) {
|
||||||
|
while (!g_buff.push(r));
|
||||||
|
r = r * 31421U + 6927U;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
rand_get();
|
||||||
|
// Create thread
|
||||||
|
m_thread_t idx_p[prod_count];
|
||||||
|
m_thread_t idx_c[conso_count];
|
||||||
|
m_thread_t idx_final;
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
size_t n2 = conso_count;
|
||||||
|
m_thread_create(idx_final, final, &n2);
|
||||||
|
|
||||||
|
// Wait for jobs to be done.
|
||||||
|
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]);
|
||||||
|
}
|
||||||
|
m_thread_join(idx_final);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/********************************************************************************************/
|
||||||
|
|
||||||
|
int main(int argc, const char *argv[])
|
||||||
|
{
|
||||||
|
int n = (argc > 1) ? atoi(argv[1]) : 0;
|
||||||
|
if (n == 60)
|
||||||
|
test_function("Buffer time", 1000000, test_buffer);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
Reference in new issue
Block a user