xref: /linux/tools/testing/selftests/powerpc/benchmarks/gettimeofday.c (revision c532de5a67a70f8533d495f8f2aaa9a0491c3ad0)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright 2015, Anton Blanchard, IBM Corp.
4  */
5 
6 #include <sys/time.h>
7 #include <stdio.h>
8 
9 #include "utils.h"
10 
11 static int test_gettimeofday(void)
12 {
13 	int i;
14 
15 	struct timeval tv_start, tv_end, tv_diff;
16 
17 	gettimeofday(&tv_start, NULL);
18 
19 	for(i = 0; i < 100000000; i++) {
20 		gettimeofday(&tv_end, NULL);
21 	}
22 
23 	timersub(&tv_start, &tv_end, &tv_diff);
24 
25 	printf("time = %.6f\n", tv_diff.tv_sec + (tv_diff.tv_usec) * 1e-6);
26 
27 	return 0;
28 }
29 
30 int main(void)
31 {
32 	return test_harness(test_gettimeofday, "gettimeofday");
33 }
34