Skip to content

Commit 703ccd6

Browse files
authored
pcre2test: use microseconds instead of milliseconds for timing (#192)
When using -t or its variants the timing results with a modern CPU where not very significant even with 4 decimal digits. While at it, move the factor calculation that can be done with integer arithmetic and even optimized out for the more common case when CLOCKS_PER_SEC == 1000000 out of the denominator.
1 parent 3fdb19c commit 703ccd6

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

src/pcre2test.c

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5899,9 +5899,8 @@ if (timeit > 0)
58995899
{ SUB1(pcre2_code_free, compiled_code); }
59005900
}
59015901
total_compile_time += time_taken;
5902-
fprintf(outfile, "Compile time %.4f milliseconds\n",
5903-
(((double)time_taken * 1000.0) / (double)timeit) /
5904-
(double)CLOCKS_PER_SEC);
5902+
fprintf(outfile, "Compile time %8.4f microseconds\n",
5903+
((1000000 / CLOCKS_PER_SEC) * (double)time_taken) / timeit);
59055904
}
59065905

59075906
/* A final compile that is used "for real". */
@@ -5932,9 +5931,8 @@ if (TEST(compiled_code, !=, NULL) && pat_patctl.jit != 0)
59325931
time_taken += clock() - start_time;
59335932
}
59345933
total_jit_compile_time += time_taken;
5935-
fprintf(outfile, "JIT compile %.4f milliseconds\n",
5936-
(((double)time_taken * 1000.0) / (double)timeit) /
5937-
(double)CLOCKS_PER_SEC);
5934+
fprintf(outfile, "JIT compile %8.4f microseconds\n",
5935+
((1000000 / CLOCKS_PER_SEC) * (double)time_taken) / timeit);
59385936
}
59395937
else
59405938
{
@@ -7687,9 +7685,8 @@ for (gmatched = 0;; gmatched++)
76877685
}
76887686
}
76897687
total_match_time += (time_taken = clock() - start_time);
7690-
fprintf(outfile, "Match time %.4f milliseconds\n",
7691-
(((double)time_taken * 1000.0) / (double)timeitm) /
7692-
(double)CLOCKS_PER_SEC);
7688+
fprintf(outfile, "Match time %7.4f microseconds\n",
7689+
((1000000 / CLOCKS_PER_SEC) * (double)time_taken) / timeitm);
76937690
}
76947691

76957692
/* Find the heap, match and depth limits if requested. The depth and heap
@@ -9493,18 +9490,16 @@ if (showtotaltimes)
94939490
fprintf(outfile, "--------------------------------------\n");
94949491
if (timeit > 0)
94959492
{
9496-
fprintf(outfile, "Total compile time %.4f milliseconds\n",
9497-
(((double)total_compile_time * 1000.0) / (double)timeit) /
9498-
(double)CLOCKS_PER_SEC);
9493+
fprintf(outfile, "Total compile time %8.2f microseconds\n",
9494+
((1000000 / CLOCKS_PER_SEC) * (double)total_compile_time) / timeit);
94999495
if (total_jit_compile_time > 0)
9500-
fprintf(outfile, "Total JIT compile %.4f milliseconds\n",
9501-
(((double)total_jit_compile_time * 1000.0) / (double)timeit) /
9502-
(double)CLOCKS_PER_SEC);
9496+
fprintf(outfile, "Total JIT compile %8.2f microseconds\n",
9497+
((1000000 / CLOCKS_PER_SEC) * (double)total_jit_compile_time) / \
9498+
timeit);
95039499
pad = " ";
95049500
}
9505-
fprintf(outfile, "Total match time %s%.4f milliseconds\n", pad,
9506-
(((double)total_match_time * 1000.0) / (double)timeitm) /
9507-
(double)CLOCKS_PER_SEC);
9501+
fprintf(outfile, "Total match time %s%8.2f microseconds\n", pad,
9502+
((1000000 / CLOCKS_PER_SEC) * (double)total_match_time) / timeitm);
95089503
}
95099504

95109505

0 commit comments

Comments
 (0)