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