xref: /dflybsd-src/test/sysperf/syscall1.c (revision d0128b6a1789e266a43d07d9baf8200378bd4596)
16b055cd4SMatthew Dillon /*
26b055cd4SMatthew Dillon  * syscall1.c
36b055cd4SMatthew Dillon  *
4*d0128b6aSMatthew Dillon  * N thread getuid timing test (default 1)
56b055cd4SMatthew Dillon  */
66b055cd4SMatthew Dillon 
76b055cd4SMatthew Dillon #include "blib.h"
86b055cd4SMatthew Dillon 
96b055cd4SMatthew Dillon int
main(int ac,char ** av)106b055cd4SMatthew Dillon main(int ac, char **av)
116b055cd4SMatthew Dillon {
126b055cd4SMatthew Dillon 	long long count = 0;
136b055cd4SMatthew Dillon 	long long max;
14e2ea6619SMatthew Dillon 	char c;
15*d0128b6aSMatthew Dillon 	int n;
16*d0128b6aSMatthew Dillon 	int i;
176b055cd4SMatthew Dillon 	int j;
18*d0128b6aSMatthew Dillon 	int status;
196b055cd4SMatthew Dillon 
20adc1b605SMatthew Dillon 	printf("timing standard getuid() syscall, single thread\n");
21adc1b605SMatthew Dillon 	printf("if using powerd, run several times\n");
226b055cd4SMatthew Dillon 
236b055cd4SMatthew Dillon 	start_timing();
246b055cd4SMatthew Dillon 	while (stop_timing(0, NULL) == 0) {
256b055cd4SMatthew Dillon 		for (j = 0; j < 100; ++j)
26c13731eaSMatthew Dillon 			getuid();
276b055cd4SMatthew Dillon 		count += 100;
286b055cd4SMatthew Dillon 	}
296b055cd4SMatthew Dillon 	max = count;
30*d0128b6aSMatthew Dillon 
31*d0128b6aSMatthew Dillon 	if (ac > 1)
32*d0128b6aSMatthew Dillon 		n = strtol(av[1], NULL, 0);
33*d0128b6aSMatthew Dillon 	else
34*d0128b6aSMatthew Dillon 		n = 1;
35*d0128b6aSMatthew Dillon 
366b055cd4SMatthew Dillon 	start_timing();
37*d0128b6aSMatthew Dillon 	for (i = 0; i < n; ++i) {
38*d0128b6aSMatthew Dillon 		if (fork() == 0) {
396b055cd4SMatthew Dillon 			for (count = 0; count < max; count += 100) {
406b055cd4SMatthew Dillon 				for (j = 0; j < 100; ++j)
41c13731eaSMatthew Dillon 					getuid();
426b055cd4SMatthew Dillon 			}
43*d0128b6aSMatthew Dillon 			_exit(0);
44*d0128b6aSMatthew Dillon 		}
45*d0128b6aSMatthew Dillon 	}
46*d0128b6aSMatthew Dillon 	while (wait3(&status, 0, NULL) >= 0 || errno == EINTR)
47*d0128b6aSMatthew Dillon 		;
48*d0128b6aSMatthew Dillon 	stop_timing(count * n, "getuid()");
49*d0128b6aSMatthew Dillon 
506b055cd4SMatthew Dillon 	return(0);
516b055cd4SMatthew Dillon }
526b055cd4SMatthew Dillon 
53