From: Laurent MAZET Date: Fri, 3 Oct 2025 16:03:17 +0000 (+0200) Subject: add a test on thread create only X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=5e9b4c670dccf534490a0b2f6ebcb5fcb730c680;p=benchmarks.git add a test on thread create only --- diff --git a/thread.c b/thread.c deleted file mode 100644 index 92cec97..0000000 --- a/thread.c +++ /dev/null @@ -1,55 +0,0 @@ -/* depend: */ -/* cflags: */ -/* linker: mtime.o test.o stat.o -lm -lpthread -lrt */ - -#include -#include - -#include "mtime.h" -#include "test.h" - -/* global variables */ - -dts_t *deltas = NULL; -int nb_measurements = 0; - -char *message = "thread"; -void (*usage_ext) (FILE *) = NULL; -int (*parse_arg_ext) (char *) = NULL; - -void* dummy_thread(void *arg) { - (void)arg; - return NULL; -} - -int test (dts_t *buffer, int nb) -{ - - /* set global variables */ - - deltas = buffer; - nb_measurements = nb; - - /* thread test */ - - for (int i = 0; i < nb_measurements; i++) { - - ts_t ts1; - sys_timestamp (&ts1); - - pthread_t posix_t; - if (pthread_create(&posix_t, NULL, dummy_thread, NULL) != 0) { - fprintf (stderr, "error on pthread_create\n"); - return 1; - } - - pthread_join(posix_t, NULL); - - ts_t ts2; - sys_timestamp (&ts2); - - deltas[i++] = diff_timestamp (&ts2, &ts1); - } - - return 0; -} diff --git a/thread_c+j.c b/thread_c+j.c new file mode 100644 index 0000000..6e10272 --- /dev/null +++ b/thread_c+j.c @@ -0,0 +1,56 @@ +/* depend: */ +/* cflags: */ +/* linker: mtime.o test.o stat.o -lm -lpthread -lrt */ + +#include +#include + +#include "mtime.h" +#include "test.h" + +/* global variables */ + +dts_t *deltas = NULL; +int nb_measurements = 0; + +char *message = "Thread (create and join) latency"; +void (*usage_ext) (FILE *) = NULL; +int (*parse_arg_ext) (char *) = NULL; + + +void* dummy_thread (__attribute__((unused)) void *arg) +{ + pthread_exit (NULL); +} + +int test (dts_t *buffer, int nb) +{ + + /* set global variables */ + + deltas = buffer; + nb_measurements = nb; + + /* thread test */ + + for (int i = 0; i < nb_measurements; i++) { + + ts_t ts1; + sys_timestamp (&ts1); + + pthread_t posix_t; + if (pthread_create(&posix_t, NULL, dummy_thread, NULL) != 0) { + fprintf (stderr, "error on pthread_create\n"); + return 1; + } + + pthread_join(posix_t, NULL); + + ts_t ts2; + sys_timestamp (&ts2); + + deltas[i] = diff_timestamp (&ts2, &ts1); + } + + return 0; +} diff --git a/thread_c.c b/thread_c.c new file mode 100644 index 0000000..d237157 --- /dev/null +++ b/thread_c.c @@ -0,0 +1,55 @@ +/* depend: */ +/* cflags: */ +/* linker: mtime.o test.o stat.o -lm -lpthread -lrt */ + +#include +#include + +#include "mtime.h" +#include "test.h" + +/* global variables */ + +dts_t *deltas = NULL; +int nb_measurements = 0; + +char *message = "Thread (create) latency"; +void (*usage_ext) (FILE *) = NULL; +int (*parse_arg_ext) (char *) = NULL; + +ts_t ts1, ts2; +int try = 0; + +void* dummy_thread (__attribute__((unused)) void *arg) +{ + sys_timestamp (&ts2); + pthread_exit (NULL); +} + +int test (dts_t *buffer, int nb) +{ + + /* set global variables */ + + deltas = buffer; + nb_measurements = nb; + + /* thread test */ + + for (int i = 0; i < nb_measurements; i++) { + + sys_timestamp (&ts1); + + pthread_t posix_t; + if (pthread_create(&posix_t, NULL, dummy_thread, NULL) != 0) { + fprintf (stderr, "error on pthread_create\n"); + return 1; + } + + pthread_join(posix_t, NULL); + + deltas[i] = diff_timestamp (&ts2, &ts1); + } + + return 0; +}