pg_test_timing: Reduce per-loop overhead

The pg_test_timing program was previously using INSTR_TIME_GET_NANOSEC on an
absolute instr_time value in order to do a diff, which goes against the spirit
of how the GET_* macros are supposed to be used, and will cause overhead in a
future change that assumes these macros are typically used on intervals only.

Additionally the program was doing unnecessary work in the test loop by
measuring the time elapsed, instead of checking the existing current time
measurement against a target end time. To support that, introduce a new
INSTR_TIME_ADD_NANOSEC macro that allows adding user-defined nanoseconds
to an instr_time variable.

While modifying the relevant code anyway, simplify it by not handling
durations <= 0 in test_timing(), since duration is unsigned and 0 is
disallowed by the caller.

Author: Lukas Fittl <[email protected]>
Reviewed-by: Andres Freund <[email protected]>
Discussion: 
https://postgr.es/m/cap53pkyxv3-3gx+aoxc5tx0p2v9rhu+xh0iyvb64+znbxj9...@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/82c0cb4e672dbc89f0bd0013c625a3a16ee36ad6

Modified Files
--------------
src/bin/pg_test_timing/pg_test_timing.c | 28 ++++++++++++++--------------
src/include/portability/instr_time.h    |  8 ++++++++
2 files changed, 22 insertions(+), 14 deletions(-)

Reply via email to