Skip to content

Commit

Permalink
powerpc/selftests: Use timersub() for gettimeofday()
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ye xingchen authored and Michael Ellerman committed Aug 22, 2022
1 parent 1c23f9e commit c814bf9
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions tools/testing/selftests/powerpc/benchmarks/gettimeofday.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ static int test_gettimeofday(void)
{
int i;

struct timeval tv_start, tv_end;
struct timeval tv_start, tv_end, tv_diff;

gettimeofday(&tv_start, NULL);

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

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

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

return 0;
}
Expand Down

0 comments on commit c814bf9

Please sign in to comment.