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