Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / bench.h
blob58a0a78d4598efeed7006029aac50be45f221a63
1 #include "test.h"
2 #include <time.h>
4 int bench_nthread;
5 int bench_niter;
6 int bench_mode;
8 void bench(); // defined by user
9 void start_thread_group(int nth, void(*f)(int tid));
11 int main(int argc, char **argv) {
12 bench_nthread = 2;
13 if (argc > 1)
14 bench_nthread = atoi(argv[1]);
15 bench_niter = 100;
16 if (argc > 2)
17 bench_niter = atoi(argv[2]);
18 if (argc > 3)
19 bench_mode = atoi(argv[3]);
21 timespec tp0;
22 clock_gettime(CLOCK_MONOTONIC, &tp0);
23 bench();
24 timespec tp1;
25 clock_gettime(CLOCK_MONOTONIC, &tp1);
26 unsigned long long t =
27 (tp1.tv_sec * 1000000000ULL + tp1.tv_nsec) -
28 (tp0.tv_sec * 1000000000ULL + tp0.tv_nsec);
29 fprintf(stderr, "%llu ns/iter\n", t / bench_niter);
30 fprintf(stderr, "DONE\n");
33 void start_thread_group(int nth, void(*f)(int tid)) {
34 pthread_t *th = (pthread_t*)malloc(nth * sizeof(pthread_t));
35 for (int i = 0; i < nth; i++)
36 pthread_create(&th[i], 0, (void*(*)(void*))f, (void*)(long)i);
37 for (int i = 0; i < nth; i++)
38 pthread_join(th[i], 0);