linux/tools/testing/selftests/powerpc/benchmarks/gettimeofday.c
ye xingchen c814bf9589 powerpc/selftests: Use timersub() for gettimeofday()
Use timersub() function to simplify the code.

Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: ye xingchen <ye.xingchen@zte.com.cn>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20220816105106.82666-1-ye.xingchen@zte.com.cn
2022-08-22 13:36:59 +10:00

34 lines
551 B
C

// 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");
}