]> git.saurik.com Git - apple/libdispatch.git/blob - testing/fork-join.c
libdispatch-84.5.5.tar.gz
[apple/libdispatch.git] / testing / fork-join.c
1 #include <mach/mach.h>
2 #include <mach/mach_time.h>
3 #include <dispatch/dispatch.h>
4 #include <dispatch/private.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <assert.h>
8
9 int
10 main(void)
11 {
12 long double nano_per_lap;
13 size_t i, cnt = 1000000;
14 dispatch_future_t *df;
15 uint64_t s, e;
16
17 df = malloc(cnt * sizeof(df));
18 assert(df);
19
20 s = mach_absolute_time();
21
22 for (i = 0; i < cnt; i++) {
23 df[i] = dispatch_fork(dispatch_get_concurrent_queue(0), ^{
24 });
25 assert(df[i]);
26 }
27
28 for (i = 0; i < cnt; i++) {
29 dispatch_join(df[i]);
30 }
31
32 e = mach_absolute_time();
33
34 nano_per_lap = (e - s);
35 nano_per_lap /= cnt;
36
37 printf("%Lf nanoseconds per lap\n", nano_per_lap);
38
39 return 0;
40 }