Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

authored by

ye xingchen and committed by
Michael Ellerman
c814bf95 1c23f9e6

+4 -2
+4 -2
tools/testing/selftests/powerpc/benchmarks/gettimeofday.c
··· 12 12 { 13 13 int i; 14 14 15 - struct timeval tv_start, tv_end; 15 + struct timeval tv_start, tv_end, tv_diff; 16 16 17 17 gettimeofday(&tv_start, NULL); 18 18 ··· 20 20 gettimeofday(&tv_end, NULL); 21 21 } 22 22 23 - printf("time = %.6f\n", tv_end.tv_sec - tv_start.tv_sec + (tv_end.tv_usec - tv_start.tv_usec) * 1e-6); 23 + timersub(&tv_start, &tv_end, &tv_diff); 24 + 25 + printf("time = %.6f\n", tv_diff.tv_sec + (tv_diff.tv_usec) * 1e-6); 24 26 25 27 return 0; 26 28 }