diff options
author | sebres <sebres@users.sourceforge.net> | 2019-05-21 18:01:07 (GMT) |
---|---|---|
committer | sebres <sebres@users.sourceforge.net> | 2019-05-21 18:01:07 (GMT) |
commit | e298c2595dd09f5e4ad00b1e42251c2ac5a4f51a (patch) | |
tree | 77e9231c5d18eacae4d6f7bf22ee320377b4d92b | |
parent | 7db84b015586fe8a54a214e3afe54e12d74fe10e (diff) | |
parent | 3ab1f672a4432f15afd982ad5857d67abd7e5db2 (diff) | |
download | tcl-e298c2595dd09f5e4ad00b1e42251c2ac5a4f51a.zip tcl-e298c2595dd09f5e4ad00b1e42251c2ac5a4f51a.tar.gz tcl-e298c2595dd09f5e4ad00b1e42251c2ac5a4f51a.tar.bz2 |
merge 8.5 (timerate unsigned calc)
-rw-r--r-- | generic/tclCmdMZ.c | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/generic/tclCmdMZ.c b/generic/tclCmdMZ.c index 1358d06..2cadce8 100644 --- a/generic/tclCmdMZ.c +++ b/generic/tclCmdMZ.c @@ -4686,17 +4686,20 @@ Tcl_TimeRateObjCmd( { Tcl_Obj *objarr[8], **objs = objarr; - Tcl_WideInt val; + Tcl_WideUInt usec, val; int digits; - middle -= start; /* execution time in microsecs */ + /* + * Absolute execution time in microseconds or in wide clicks. + */ + usec = (Tcl_WideUInt)(middle - start); #ifdef TCL_WIDE_CLICKS /* - * convert execution time in wide clicks to microsecs. + * convert execution time (in wide clicks) to microsecs. */ - middle *= TclpWideClickInMicrosec(); + usec *= TclpWideClickInMicrosec(); #endif /* TCL_WIDE_CLICKS */ if (!count) { /* no iterations - avoid divide by zero */ @@ -4720,10 +4723,10 @@ Tcl_TimeRateObjCmd( Tcl_WideUInt curOverhead = overhead * count; - if ((Tcl_WideUInt) middle > curOverhead) { - middle -= curOverhead; + if (usec > curOverhead) { + usec -= curOverhead; } else { - middle = 0; + usec = 0; } } } else { @@ -4731,15 +4734,15 @@ Tcl_TimeRateObjCmd( * Calibration: obtaining new measurement overhead. */ - if (measureOverhead > ((double) middle) / count) { - measureOverhead = ((double) middle) / count; + if (measureOverhead > ((double) usec) / count) { + measureOverhead = ((double) usec) / count; } objs[0] = Tcl_NewDoubleObj(measureOverhead); TclNewLiteralStringObj(objs[1], "\xC2\xB5s/#-overhead"); /* mics */ objs += 2; } - val = middle / count; /* microsecs per iteration */ + val = usec / count; /* microsecs per iteration */ if (val >= 1000000) { objs[0] = Tcl_NewWideIntObj(val); } else { @@ -4754,7 +4757,7 @@ Tcl_TimeRateObjCmd( } else { digits = 1; } - objs[0] = Tcl_ObjPrintf("%.*f", digits, ((double) middle)/count); + objs[0] = Tcl_ObjPrintf("%.*f", digits, ((double) usec)/count); } objs[2] = Tcl_NewWideIntObj(count); /* iterations */ @@ -4763,11 +4766,11 @@ Tcl_TimeRateObjCmd( * Calculate speed as rate (count) per sec */ - if (!middle) { - middle++; /* Avoid divide by zero. */ + if (!usec) { + usec++; /* Avoid divide by zero. */ } if (count < (WIDE_MAX / 1000000)) { - val = (count * 1000000) / middle; + val = (count * 1000000) / usec; if (val < 100000) { if (val < 100) { digits = 3; @@ -4777,12 +4780,12 @@ Tcl_TimeRateObjCmd( digits = 1; } objs[4] = Tcl_ObjPrintf("%.*f", - digits, ((double) (count * 1000000)) / middle); + digits, ((double) (count * 1000000)) / usec); } else { objs[4] = Tcl_NewWideIntObj(val); } } else { - objs[4] = Tcl_NewWideIntObj((count / middle) * 1000000); + objs[4] = Tcl_NewWideIntObj((count / usec) * 1000000); } retRes: @@ -4791,8 +4794,8 @@ Tcl_TimeRateObjCmd( */ if (!calibrate) { - if (middle >= 1) { - objs[6] = Tcl_ObjPrintf("%.3f", (double)middle / 1000); + if (usec >= 1) { + objs[6] = Tcl_ObjPrintf("%.3f", (double)usec / 1000); } else { objs[6] = Tcl_NewWideIntObj(0); } |