tsan: do not sleep at exit if there are no other threads
[blocksruntime.git] / test / timing / timing.h
blobbb6c41eb2a625435777d8ff5f2b000c4bac6f50c
1 #include <mach/mach_time.h>
2 #include <stdint.h>
3 #include <stdlib.h>
5 double intervalInCycles( uint64_t startTime, uint64_t endTime )
7 uint64_t rawTime = endTime - startTime;
8 static double conversion = 0.0;
10 if( 0.0 == conversion )
12 mach_timebase_info_data_t info;
13 kern_return_t err = mach_timebase_info( &info );
14 if( 0 != err )
15 return 0;
17 uint64_t freq = 0;
18 size_t freqSize = sizeof( freq );
19 int err2 = sysctlbyname( "hw.cpufrequency", &freq, &freqSize, NULL, 0L );
20 if( 0 != err2 )
21 return 0;
23 conversion = (double) freq * (1e-9 * (double) info.numer / (double) info.denom);
26 return (double) rawTime * conversion;