pthread bench from libc-bench
authornsz <nsz@port70.net>
Thu, 4 Aug 2011 23:55:17 +0000 (01:55 +0200)
committernsz <nsz@port70.net>
Thu, 4 Aug 2011 23:55:17 +0000 (01:55 +0200)
src/thread/bench.c [new file with mode: 0644]
src/thread/sem.c

diff --git a/src/thread/bench.c b/src/thread/bench.c
new file mode 100644 (file)
index 0000000..10937aa
--- /dev/null
@@ -0,0 +1,106 @@
+#define _XOPEN_SOURCE 700
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <pthread.h>
+#include <unistd.h>
+#include "test.h"
+
+void *emptyfunc(void *dummy) {
+       return 0;
+}
+
+void bench_pthread_createjoin_serial1(int N) {
+       int i;
+       pthread_t td;
+       void *dummy;
+
+       for (i=0; i<N; i++) {
+               pthread_create(&td, 0, emptyfunc, 0);
+               pthread_join(td, &dummy);
+       }
+}
+
+void bench_pthread_createjoin_serial2(int N) {
+       int i, j;
+       pthread_t td[50];
+       void *dummy;
+
+       for (j=0; j<N/(sizeof td/sizeof *td); j++) {
+               for (i=0; i<sizeof td/sizeof *td; i++)
+                       pthread_create(td+i, 0, emptyfunc, 0);
+               for (i=0; i<sizeof td/sizeof *td; i++)
+                       pthread_join(td[i], &dummy);
+       }
+}
+
+void bench_pthread_create_serial1(int N) {
+       int i,j;
+       pthread_attr_t attr;
+       pthread_t td[50];
+       void *dummy;
+
+       pthread_attr_init(&attr);
+       pthread_attr_setstacksize(&attr, 16384);
+       for (j=0; j<N/(sizeof td/sizeof *td); j++) {
+               for (i=0; i<sizeof td/sizeof *td; i++)
+                       pthread_create(td+i, &attr, emptyfunc, 0);
+               stop_timer();
+               for (i=0; i<sizeof td/sizeof *td; i++)
+                       pthread_join(td[i], &dummy);
+               start_timer();
+       }
+}
+
+static int lockN;
+void *lockunlock(void *mut)
+{
+       int i;
+       for (i=0; i<lockN; i++) {
+               pthread_mutex_lock(mut);
+               pthread_mutex_unlock(mut);
+       }
+       return 0;
+}
+
+void bench_pthread_uselesslock(int N) {
+       pthread_t td;
+       pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER;
+       void *dummy;
+
+       lockN = N;
+       pthread_create(&td, 0, lockunlock, &mut);
+       pthread_join(td, &dummy);
+}
+
+void bench_pthread_createjoin_min1(int N) {
+       size_t i;
+       pthread_t td;
+       pthread_attr_t a;
+       void *dummy;
+
+       pthread_attr_init(&a);
+       pthread_attr_setstacksize(&a, sysconf(_SC_PAGESIZE));
+       pthread_attr_setguardsize(&a, 0);
+       for (i=0; i<N; i++) {
+               pthread_create(&td, &a, emptyfunc, 0);
+               pthread_join(td, &dummy);
+       }
+}
+
+void bench_pthread_createjoin_min2(int N) {
+       int i, j;
+       pthread_t td[50];
+       pthread_attr_t a;
+       void *dummy;
+
+       pthread_attr_init(&a);
+       pthread_attr_setstacksize(&a, sysconf(_SC_PAGESIZE));
+       pthread_attr_setguardsize(&a, 0);
+       for (j=0; j<N/(sizeof td/sizeof *td); j++) {
+               for (i=0; i<sizeof td/sizeof *td; i++)
+                       pthread_create(td+i, &a, emptyfunc, 0);
+               for (i=0; i<sizeof td/sizeof *td; i++)
+                       pthread_join(td[i], &dummy);
+       }
+}
index 6840cd2..5bfcdfe 100644 (file)
@@ -21,7 +21,6 @@
 void test_sem(void)
 {
        int r;
-       void *res;
        char buf[100];
        struct timespec ts;
        sem_t *sem, *sem2;