v2 -- rearranged a little more nicely.
Patch (apply with `patch -p0'):
--- builtins/reserved.def
+++ ../bash-5.3-patched/builtins/reserved.def Mon Sep 22 20:35:06 2025
@@ -91,6 +91,8 @@
-p print the timing summary in the portable Posix format
The value of the TIMEFORMAT variable is used as the output format.
+The value of the TIMEREPEAT variable is used to indicate the number
+of times the pipline will be ran before the total time is measured.
Exit Status:
The return status is the return status of PIPELINE.
--- execute_cmd.c
+++ ../bash-5.3-patched/execute_cmd.c Tue Sep 23 06:25:31 2025
@@ -1436,6 +1436,15 @@
char *time_format;
volatile procenv_t save_top_level;
volatile int old_subshell, old_flags;
+
+/* If variable TIMEREPEAT exists, and if it is set to an integer
+ N>1, then time_command will execute the pipeline N times
+ between the "before" and "after" time-readings. */
+
+ intmax_t nrepeat;
+ char *vrepeat = get_string_value ("TIMEREPEAT");
+ if (vrepeat == 0 || *vrepeat == 0 || valid_number (vrepeat, &nrepeat) == 0
|| nrepeat < 1)
+ nrepeat = 1;
#if defined (HAVE_GETRUSAGE) && defined (HAVE_GETTIMEOFDAY)
struct timeval real, user, sys;
@@ -1487,7 +1496,8 @@
command->flags &= ~(CMD_TIME_PIPELINE|CMD_TIME_POSIX);
code = setjmp_nosigs (top_level);
if (code == NOT_JUMPED)
- rv = execute_command_internal (command, asynchronous, pipe_in, pipe_out,
fds_to_close);
+ while (nrepeat--)
+ rv = execute_command_internal (command, asynchronous, pipe_in, pipe_out,
fds_to_close);
COPY_PROCENV (save_top_level, top_level);
if (code == NOT_JUMPED)
--
2.51.0