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