Why does my script run at half speed after the first run
Posted: 26 Feb 2012 16:28
The Script TickTock.bat below can make a very rapid measurement of a interval of time between one %TICK% or %TOCK% and the next %TOCK%
It does this by executing code within a variable, and is about 15 times faster than when I used "CALL :TOCK" to run code at the bottom of the script.
It can perform 50 off %TOCK% measurements in about 60 mSec (1.2 mSec per measurement) when
a) I launch the script by double clicking the file in Windows Explorer ;
b) Launching CMD.EXE and invoking "TickTock #", which will repeatedly START a second instance of itself to do the 60 mSec job
c) Launching CMD.EXE and invoking TickTock - BUT ONLY ONCE PER INSTANCE - once it has run this same instance of CMD.EXE takes 130 mSec
The third line of code is "SET > SET.TXT" and this is subsequently renamed.
There is absolutely no difference between the Environmental Variables captured at the start of the script when launched by modes (a), (b), or (c and repeated)
i.e. when it runs at half speed the Environmental Variables were NOT affected by previous history/experience of this same instance of CMD.EXE
Why does it go slow after the first operation ?
Does CMD.EXE keep the variables in sorted order, and when my variables are added and values changed the memory locations change and gaps get left,
and that "experience" and extra gaps actually hinder instead of help future use of the same variables ?
Should I prefix all my variables with lower case 'z' so they go at the end and cause no gaps ? or is it sorted reverse order ?
I would appreciate advice and suggestions on how to fix the code so that having launched CMD.EXE and run TickTock once,
I only need to hit the up arrow and then hit Return to rerun the same code in the same instance - at full speed.
Incidentally, there are 244 character on the line starting
SET "TOCK=SET
I tried splitting into two lines with a '^' at the end of the first line, but that just broke my code.
Enhanced TickTock.bat now appears in post below.
It still behaves exactly as the first version.
Regards
Alan
It does this by executing code within a variable, and is about 15 times faster than when I used "CALL :TOCK" to run code at the bottom of the script.
It can perform 50 off %TOCK% measurements in about 60 mSec (1.2 mSec per measurement) when
a) I launch the script by double clicking the file in Windows Explorer ;
b) Launching CMD.EXE and invoking "TickTock #", which will repeatedly START a second instance of itself to do the 60 mSec job
c) Launching CMD.EXE and invoking TickTock - BUT ONLY ONCE PER INSTANCE - once it has run this same instance of CMD.EXE takes 130 mSec
The third line of code is "SET > SET.TXT" and this is subsequently renamed.
There is absolutely no difference between the Environmental Variables captured at the start of the script when launched by modes (a), (b), or (c and repeated)
i.e. when it runs at half speed the Environmental Variables were NOT affected by previous history/experience of this same instance of CMD.EXE
Why does it go slow after the first operation ?
Does CMD.EXE keep the variables in sorted order, and when my variables are added and values changed the memory locations change and gaps get left,
and that "experience" and extra gaps actually hinder instead of help future use of the same variables ?
Should I prefix all my variables with lower case 'z' so they go at the end and cause no gaps ? or is it sorted reverse order ?
I would appreciate advice and suggestions on how to fix the code so that having launched CMD.EXE and run TickTock once,
I only need to hit the up arrow and then hit Return to rerun the same code in the same instance - at full speed.
Incidentally, there are 244 character on the line starting
SET "TOCK=SET
I tried splitting into two lines with a '^' at the end of the first line, but that just broke my code.
Enhanced TickTock.bat now appears in post below.
It still behaves exactly as the first version.
Regards
Alan