1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <unistd.h> 4 #include <sys/stat.h> 5 #include <mach/mach_time.h> 6 #include <sys/time.h> 7 8 #include <darwintest.h> 9 #include <darwintest_perf.h> 10 11 T_GLOBAL_META(T_META_TAG_PERF); 12 13 T_DECL(gettimeofday_tl, "gettimeofday performance in tight loop") { 14 { 15 struct timeval time; 16 dt_stat_time_t s = dt_stat_time_create("gettimeofday tight loop"); T_STAT_MEASURE_LOOP(s)17 T_STAT_MEASURE_LOOP(s){ 18 gettimeofday(&time, NULL); 19 } 20 dt_stat_finalize(s); 21 } 22 } 23 24 extern int __gettimeofday(struct timeval *, struct timezone *); 25 T_DECL(__gettimeofday_tl, "__gettimeofday performance in tight loop") { 26 { 27 struct timeval time; 28 29 dt_stat_time_t s = dt_stat_time_create("__gettimeofday tight loop"); T_STAT_MEASURE_LOOP(s)30 T_STAT_MEASURE_LOOP(s){ 31 __gettimeofday(&time, NULL); 32 } 33 dt_stat_finalize(s); 34 } 35 } 36 37 T_DECL(gettimeofday_sl, "gettimeofday performance in loop with sleep") { 38 { 39 struct timeval time; 40 dt_stat_time_t s = dt_stat_time_create("gettimeofday loop with sleep"); 41 while (!dt_stat_stable(s)) { T_STAT_MEASURE_BATCH(s)42 T_STAT_MEASURE_BATCH(s){ 43 gettimeofday(&time, NULL); 44 } 45 sleep(1); 46 } 47 dt_stat_finalize(s); 48 } 49 } 50