diff options
| -rw-r--r-- | generic/tclCmdMZ.c | 12 | ||||
| -rw-r--r-- | tests/cmdMZ.test | 7 |
2 files changed, 16 insertions, 3 deletions
diff --git a/generic/tclCmdMZ.c b/generic/tclCmdMZ.c index 831c3c4..cf4625e 100644 --- a/generic/tclCmdMZ.c +++ b/generic/tclCmdMZ.c @@ -4385,6 +4385,11 @@ usage: middle *= TclpWideClickInMicrosec(); #endif + if (!count) { /* no iterations - avoid divide by zero */ + objs[0] = objs[2] = objs[4] = Tcl_NewWideIntObj(0); + goto retRes; + } + /* if not calibrate */ if (!calibrate) { /* minimize influence of measurement overhead */ @@ -4437,9 +4442,14 @@ usage: objs[4] = Tcl_NewWideIntObj((count / middle) * 1000000); } + retRes: /* estimated net execution time (in millisecs) */ if (!calibrate) { - objs[6] = Tcl_ObjPrintf("%.3f", (double)middle / 1000); + if (middle >= 1) { + objs[6] = Tcl_ObjPrintf("%.3f", (double)middle / 1000); + } else { + objs[6] = Tcl_NewWideIntObj(0); + } TclNewLiteralStringObj(objs[7], "nett-ms"); } diff --git a/tests/cmdMZ.test b/tests/cmdMZ.test index 45231c8..d79e9f6 100644 --- a/tests/cmdMZ.test +++ b/tests/cmdMZ.test @@ -360,8 +360,11 @@ test cmdMZ-6.3 {Tcl_TimeRateObjCmd: basic format of command} { test cmdMZ-6.4 {Tcl_TimeRateObjCmd: compile of script happens even with negative iteration counts} { list [catch {timerate "foreach a {c d e} \{" -12456} msg] $msg } {1 {missing close-brace}} -test cmdMZ-6.5 {Tcl_TimeRateObjCmd: result format and one iteration} { - regexp {^\d+.\d+ \ws/# 1 # \d+ #/sec \d+.\d+ nett-ms$} [timerate {} 0] +test cmdMZ-6.5a {Tcl_TimeRateObjCmd: result format and one iteration} { + regexp {^\d+(?:\.\d+)? \ws/# 1 # \d+(?:\.\d+)? #/sec \d+(?:\.\d+)? nett-ms$} [timerate {} 0] +} 1 +test cmdMZ-6.5b {Tcl_TimeRateObjCmd: result format without iterations} { + regexp {^0 \ws/# 0 # 0 #/sec 0 nett-ms$} [timerate {} 0 0] } 1 test cmdMZ-6.6 {Tcl_TimeRateObjCmd: slower commands take longer, but it remains almost the same time of measument} { set m1 [timerate {after 0} 20] |
