summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authorsebres <sebres@users.sourceforge.net>2017-02-07 19:35:51 (GMT)
committersebres <sebres@users.sourceforge.net>2017-02-07 19:35:51 (GMT)
commitb9a4ebb568a0433ab24abb6ea609d4bda6fd337a (patch)
tree06b630ddf43d66e47fe562708da6a4cce980ec67 /generic
parentde7fe4dd0fea3795e66e91109721ce68c5d7005b (diff)
downloadtcl-mistake.zip
tcl-mistake.tar.gz
tcl-mistake.tar.bz2
[timerate] bug fix: missing scale conversion by Mac OSX on platform where high resolution clicks are not microseconds based;mistake
[win] use high resolution timer for the wide clicks and microseconds directly, prevent several forwards/backwards conversions; [win, unix, mac-osx] normalize some functions for common usage in different time units (clicks, micro- and nanoseconds) # Conflicts: # win/tclWinTime.c
Diffstat (limited to 'generic')
-rw-r--r--generic/tclClock.c9
-rw-r--r--generic/tclCmdMZ.c24
-rw-r--r--generic/tclInt.h16
3 files changed, 34 insertions, 15 deletions
diff --git a/generic/tclClock.c b/generic/tclClock.c
index 27009fd..5da9511 100644
--- a/generic/tclClock.c
+++ b/generic/tclClock.c
@@ -1760,8 +1760,7 @@ ClockClicksObjCmd(
#endif
break;
case CLICKS_MICROS:
- Tcl_GetTime(&now);
- clicks = ((Tcl_WideInt) now.sec * 1000000) + now.usec;
+ clicks = TclpGetMicroseconds();
break;
}
@@ -1831,15 +1830,11 @@ ClockMicrosecondsObjCmd(
int objc, /* Parameter count */
Tcl_Obj *const *objv) /* Parameter values */
{
- Tcl_Time now;
-
if (objc != 1) {
Tcl_WrongNumArgs(interp, 1, objv, NULL);
return TCL_ERROR;
}
- Tcl_GetTime(&now);
- Tcl_SetObjResult(interp, Tcl_NewWideIntObj(
- ((Tcl_WideInt) now.sec * 1000000) + now.usec));
+ Tcl_SetObjResult(interp, Tcl_NewWideIntObj(TclpGetMicroseconds()));
return TCL_OK;
}
diff --git a/generic/tclCmdMZ.c b/generic/tclCmdMZ.c
index c660596..586e87a 100644
--- a/generic/tclCmdMZ.c
+++ b/generic/tclCmdMZ.c
@@ -4215,16 +4215,19 @@ usage:
}
/* get start and stop time */
-#ifndef TCL_WIDE_CLICKS
+#ifdef TCL_WIDE_CLICKS
+ start = middle = TclpGetWideClicks();
+ /* time to stop execution (in wide clicks) */
+ stop = start + (maxms * 1000 / TclpWideClickInMicrosec());
+#else
Tcl_GetTime(&now);
start = now.sec; start *= 1000000; start += now.usec;
-#else
- start = TclpGetWideClicks();
+ middle = start;
+ /* time to stop execution (in microsecs) */
+ stop = start + maxms * 1000;
#endif
/* start measurement */
- stop = start + maxms * 1000;
- middle = start;
while (1) {
/* eval single iteration */
count++;
@@ -4246,11 +4249,11 @@ usage:
if (--threshold > 0) continue;
/* check stop time reached, estimate new threshold */
- #ifndef TCL_WIDE_CLICKS
+ #ifdef TCL_WIDE_CLICKS
+ middle = TclpGetWideClicks();
+ #else
Tcl_GetTime(&now);
middle = now.sec; middle *= 1000000; middle += now.usec;
- #else
- middle = TclpGetWideClicks();
#endif
if (middle >= stop) {
break;
@@ -4274,6 +4277,11 @@ usage:
middle -= start; /* execution time in microsecs */
+ #ifdef TCL_WIDE_CLICKS
+ /* convert execution time in wide clicks to microsecs */
+ middle *= TclpWideClickInMicrosec();
+ #endif
+
/* if not calibrate */
if (!calibrate) {
/* minimize influence of measurement overhead */
diff --git a/generic/tclInt.h b/generic/tclInt.h
index 1b37d84..387bd5e 100644
--- a/generic/tclInt.h
+++ b/generic/tclInt.h
@@ -3189,7 +3189,23 @@ MODULE_SCOPE void TclFinalizeThreadStorage(void);
#ifdef TCL_WIDE_CLICKS
MODULE_SCOPE Tcl_WideInt TclpGetWideClicks(void);
MODULE_SCOPE double TclpWideClicksToNanoseconds(Tcl_WideInt clicks);
+MODULE_SCOPE double TclpWideClickInMicrosec(void);
+#else
+# ifdef _WIN32
+# define TCL_WIDE_CLICKS 1
+MODULE_SCOPE Tcl_WideInt TclpGetWideClicks(void);
+# define TclpWideClicksToNanoseconds(clicks) \
+ ((double)clicks / 1000)
+# define TclpWideClickInMicrosec() (1)
+# endif
#endif
+#ifndef _WIN32
+MODULE_SCOPE Tcl_WideInt TclpGetMicroseconds(void);
+#else
+# define TclpGetMicroseconds() \
+ TclpGetWideClicks()
+#endif
+
MODULE_SCOPE int TclZlibInit(Tcl_Interp *interp);
MODULE_SCOPE void * TclpThreadCreateKey(void);
MODULE_SCOPE void TclpThreadDeleteKey(void *keyPtr);