summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/powerpc/benchmarks/gettimeofday.c
blob: 580fcac0a09f31bf284d46c97f25148c96909386 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright 2015, Anton Blanchard, IBM Corp.
 */

#include <sys/time.h>
#include <stdio.h>

#include "utils.h"

static int test_gettimeofday(void)
{
	int i;

	struct timeval tv_start, tv_end, tv_diff;

	gettimeofday(&tv_start, NULL);

	for(i = 0; i < 100000000; i++) {
		gettimeofday(&tv_end, NULL);
	}

	timersub(&tv_start, &tv_end, &tv_diff);

	printf("time = %.6f\n", tv_diff.tv_sec + (tv_diff.tv_usec) * 1e-6);

	return 0;
}

int main(void)
{
	return test_harness(test_gettimeofday, "gettimeofday");
}