TIMER command

May 20, 2008
11,400
99
Syracuse, NY, USA
This snippet looks pretty good. TIMER reports reasonable numbers.
Code:
v:\> do forever ( timer & echo %@ping[www.syr.edu,5] & timer )
Timer 1 on: 13:16:46
83
Timer 1 off: 13:16:46  Elapsed: 0:00:00.09
Timer 1 on: 13:16:46
85
Timer 1 off: 13:16:46  Elapsed: 0:00:00.08
Timer 1 on: 13:16:46
84
Timer 1 off: 13:16:46  Elapsed: 0:00:00.10
Timer 1 on: 13:16:46
-1
Timer 1 off: 13:16:51  Elapsed: 0:00:05.00
Timer 1 on: 13:16:51
83
Timer 1 off: 13:16:52  Elapsed: 0:00:00.08
But when I use the shortened version of the TIMER command, I get unreasonable numbers; they're all too small, especially the one after a 5 second timeout.
Code:
do forever ( timer echo %@ping[www.syr.edu,5] )
Timer 1 on: 13:17:30
86
Timer 1 off: 13:17:30  Elapsed: 0:00:00.01
Timer 1 on: 13:17:30
85
Timer 1 off: 13:17:30  Elapsed: 0:00:00.00
Timer 1 on: 13:17:35
-1
Timer 1 off: 13:17:35  Elapsed: 0:00:00.00   <== I watched it wait for 5 seconds
Timer 1 on: 13:17:35
84
Timer 1 off: 13:17:35  Elapsed: 0:00:00.00
 

rconn

Administrator
Staff member
May 14, 2008
12,344
149
But when I use the shortened version of the TIMER command, I get unreasonable numbers; they're all too small, especially the one after a 5 second timeout.

Leaving aside the question of exactly why you would want to time an already timed command ...

This doesn't have anything to do with DO, or even TIMER. @PING is resetting the timer.
 
May 20, 2008
11,400
99
Syracuse, NY, USA
W
Leaving aside the question of exactly why you would want to time an already timed command ...

This doesn't have anything to do with DO, or even TIMER. @PING is resetting the timer.
Why then does the longer construct
Code:
do forever ( timer & echo %@ping[www.syr.edu,5] & timer )
get it right?

And (re Rex's reply to Steve), I see the same problem with the short version of TIMER when I use my plugin @ICMP or my plugin @CONNECT (TCP by port) instead of @PING. I assure you they do nothing with the system clock. @CONNECT simply calls QueryPerformanceCounter() twice and @ICMP simply reads ICMP_ECHO_REPLY::RoundTripTime.
 
May 20, 2008
11,400
99
Syracuse, NY, USA
OK. I see what's going on and it seems right. In my original example,
Code:
do forever ( timer echo %@ping[www.syr.edu,5] )
@PING is evaluated when the command line is parsed. Even if that results in a timeout, the command turns into
Code:
timer echo -1
which happens very fast. It was my fault for thinking TIMER (short version) would postpone evaluating variables on it's command line.
Code:
timer echo %%ping[www.syr.edu,5]
works as I would expect.
 
May 20, 2008
3,515
4
Elkridge, MD, USA
No, Vince - just look at the lines displayed by ECHO in your OP - each ping-time is different from previous and subsequent ones, cannot be from a single evaluation on the first pass. In fact I think the command group itself is probably not fully parsed until it is actually executed (and at least partially reparsed for each execution).

I suspect the actual issue is a race condition between multiple timers, the ones in the code for the @PING function (at least two: one for measuring, and one for timeout) and the one used by the TIMER command.

Rex: users do not care whether an erroneous report came from TCC or from Windows (or any other source). If a certain combination of TCC internal features does not provide dependable results, users blame TCC, even as I (who should have known better) did when I wrote a TCC batch program with a race condition, until I found my own mistake. So maybe all timing features ought to have a warning about race conditions. If we dealt with a programming language intended only for professional programmers, such a C/C++/Fortran/etc., they would be expected to know about race conditions and how to avoid them, but scripting languages are intended for the non-professionals (or worse, the quasiprofessionals) who may have never heard of the phenomenon, so it would promote TCMD's acceptance to include appropriate warnings.
 
May 20, 2008
11,400
99
Syracuse, NY, USA
I'm not sure about that. Think of it:
Code:
do forever ( timer echo %@ping[...] )
DO looks at its command (timer echo %@ping[...]). The command is parsed, variables evaluated ... ( timer echo -1 ); that took 5 seconds. The command is then executed (very fast) and TIMER reports 0.
Then DO does it again; @ping is re-evaluated, but before the TIMER command is executed.
You can leave DO out of the discussion. It's a matter of when @ping[] is evaluated:
Code:
v:\> timer echo %@ping[128.230.13.42,5]
Timer 1 on: 12:57:37
-1
Timer 1 off: 12:57:37  Elapsed: 0:00:00.00  ("timer echo -1" was executed)

v:\> timer echo %%@ping[128.230.13.42,5]
Timer 1 on: 12:57:44
-1
Timer 1 off: 12:57:49  Elapsed: 0:00:05.01

I think I've got it right. Am I still missing something?
 
May 20, 2008
3,515
4
Elkridge, MD, USA
Your conjecture may be right, Vince, that @PING is actually executed before TIMER is started. I tried a command, COPY of a 590MB file, instead of the function @PING; the report was reasonable. (2 min 58s). I am not sure there is any interference from @PING with the timer. I need to leave, but you might try using the PING command (I know it is external) instead of @PING; you might also try the DELAY command, which does use TCC and WinAPI to achieve delays, to see what's reported.
 
Similar threads
Thread starter Title Forum Replies Date
vefatica TIMER command Support 2
B Two Issues With TIMER Command In V14 Support 10
Joe Caverly PAUSE does not erase countdown timer Support 0
vefatica @TIMER's format ... Support 2
samintz Timer issue Support 4
vefatica TIMER causes confusion Support 2
vefatica @TIMER's second parameter? Support 3
vefatica TIMER off by factor of 10 (or even 100) Support 4
J TCC 25 @TIMER regession Support 4
jbanaszczyk %@Timer Support 1
D TIMER OFF doesn't work Support 21
H TIMER bug Support 4
gunkelkarl timer ? Support 3
Dmitry L. Kobyakov How to? How to remove the record of the old version of the Take Command? Support 5
D Can alias pass parameters to for command? Support 3
samintz How to? Search for %(command) in Help? Support 1
T VIEW only works from command line Support 14
rconn News Take Command / TCC / CMDebug / TCC-RT v28 Released Support 0
T Take Command 28: Lua reports version 5.4.0 (5.4.3 expected) Support 0
Jay Sage WAD Possible Bug With OPTION Command With @FILE Support 5
rconn News Take Command / TCC / CMDebug / TCC-RT 27.01.24 uploaded Support 0
J Take command does not start on Windows 10 Support 3
vefatica `Back quotes` - command line vs. batch file Support 5
Jay Sage WAD Failure of Alias Command with /Z Option Support 14
Phileosophos Is there any way to open the Take Command options dialog from the command line? Support 8
Phileosophos Command-line Editing Shortkeys That Fail Support 6
fpefpe How to? free (internal) command Support 0
rconn News Take Command / TCC / CMDebug / TCC-RT 27.01.23 uploaded Support 0
T How to? retain command history across reboot? Support 6
rconn News Take Command / TCC / CMDebug / TCC-RT v27.01 Build 22 Uploaded Support 0
Jay Sage Bug With Flow Control and/or Command Grouping Support 2
GermanDirk How to? EVENTLOG Command with simple User Rights not functional Support 4
Jay Sage Take Command Is Too Fast! Support 4
Jay Sage Comparison of IF with Command Group and IFF Support 6
D Open Windows 10 Photos app from command line Support 11
rconn News Take Command / TCC / CMDebug / TCC-RT 27.0.21 uploaded Support 0
rconn News Take Command / TCC / CMDebug / TCC-RT 27.0.20 uploaded Support 0
U Can not get/start Take Command gui Support 1
rconn News Take Command / TCC / CMDebug / TCC-RT 27.0.19 Support 0
S Increasing Font Point Size in Command Tabs Support 2
mfarah Fixed The DATE command produces the wrong error message. Support 1
vefatica Command name mix-up Support 3
FreezerBurnt "Missing SETLOCAL" when initializing Visual Studio Command Prompt. Support 9
E How to? Closing desktop created by DESKTOP command Support 10
rconn News Take Command / TCC / CMDebug / TCC-RT v27.0.18 Support 0
K Take Command fox XP? Support 7
Joe Caverly Documentation Replace internal command with LIBRARY command Support 0
fpefpe How to? command echo in title line/bar Support 2
U Command help on file names Support 5
vefatica Command line DO with no closing parenthesis? Support 9

Similar threads