Skip to content

Commit

Permalink
pcre2test: use microseconds instead of milliseconds for timing (#192)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
carenas authored Jan 19, 2023
1 parent 3fdb19c commit 703ccd6
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions src/pcre2test.c
Original file line number Diff line number Diff line change
Expand Up @@ -5899,9 +5899,8 @@ if (timeit > 0)
{ SUB1(pcre2_code_free, compiled_code); }
}
total_compile_time += time_taken;
fprintf(outfile, "Compile time %.4f milliseconds\n",
(((double)time_taken * 1000.0) / (double)timeit) /
(double)CLOCKS_PER_SEC);
fprintf(outfile, "Compile time %8.4f microseconds\n",
((1000000 / CLOCKS_PER_SEC) * (double)time_taken) / timeit);
}

/* A final compile that is used "for real". */
Expand Down Expand Up @@ -5932,9 +5931,8 @@ if (TEST(compiled_code, !=, NULL) && pat_patctl.jit != 0)
time_taken += clock() - start_time;
}
total_jit_compile_time += time_taken;
fprintf(outfile, "JIT compile %.4f milliseconds\n",
(((double)time_taken * 1000.0) / (double)timeit) /
(double)CLOCKS_PER_SEC);
fprintf(outfile, "JIT compile %8.4f microseconds\n",
((1000000 / CLOCKS_PER_SEC) * (double)time_taken) / timeit);
}
else
{
Expand Down Expand Up @@ -7687,9 +7685,8 @@ for (gmatched = 0;; gmatched++)
}
}
total_match_time += (time_taken = clock() - start_time);
fprintf(outfile, "Match time %.4f milliseconds\n",
(((double)time_taken * 1000.0) / (double)timeitm) /
(double)CLOCKS_PER_SEC);
fprintf(outfile, "Match time %7.4f microseconds\n",
((1000000 / CLOCKS_PER_SEC) * (double)time_taken) / timeitm);
}

/* Find the heap, match and depth limits if requested. The depth and heap
Expand Down Expand Up @@ -9493,18 +9490,16 @@ if (showtotaltimes)
fprintf(outfile, "--------------------------------------\n");
if (timeit > 0)
{
fprintf(outfile, "Total compile time %.4f milliseconds\n",
(((double)total_compile_time * 1000.0) / (double)timeit) /
(double)CLOCKS_PER_SEC);
fprintf(outfile, "Total compile time %8.2f microseconds\n",
((1000000 / CLOCKS_PER_SEC) * (double)total_compile_time) / timeit);
if (total_jit_compile_time > 0)
fprintf(outfile, "Total JIT compile %.4f milliseconds\n",
(((double)total_jit_compile_time * 1000.0) / (double)timeit) /
(double)CLOCKS_PER_SEC);
fprintf(outfile, "Total JIT compile %8.2f microseconds\n",
((1000000 / CLOCKS_PER_SEC) * (double)total_jit_compile_time) / \
timeit);
pad = " ";
}
fprintf(outfile, "Total match time %s%.4f milliseconds\n", pad,
(((double)total_match_time * 1000.0) / (double)timeitm) /
(double)CLOCKS_PER_SEC);
fprintf(outfile, "Total match time %s%8.2f microseconds\n", pad,
((1000000 / CLOCKS_PER_SEC) * (double)total_match_time) / timeitm);
}


Expand Down

0 comments on commit 703ccd6

Please sign in to comment.