
Re: Why does my script run at half speed after the first run
My previous code was fully functional and did the job, but was rushed out before I went to bed.
I have now seen and corrected some typos and greatly improved the structure of the code.
The results with my new code are identical to the old code.
To avoid confusion I am placing my new code here, and removing the old code from the post above.
Code:
@echo off & SETLOCAL DISABLEDELAYEDEXPANSION
ECHO FILE %0 CREATED 20:12 24/02/2012 Launched %TIME%
SET > SET.TXT
REM ----------------------------------------- SPECIAL START SPEED C0NTROL CODE BEGINNING
IF "%1"=="#" ECHO STARTing %0 :PROC & START "" /LOW /WAIT %0 :PROC & EXIT /B
IF "%1"==":PROC" CALL %1 & EXIT
REM ---------------------------------------- SPECIAL START SPEED C0NTROL CODE CONCLUSION
:PROC
SET "TICK=SET "T_X=!TIME!" & FOR /F "tokens=1-4 delims=:." %%d in ("!T_X!") do (SET /A V_X=%%d*360000+1%%e*6000+1%%f*100+1%%g-610100)"
SET "TOCK=SET "T_1=!T_X!" & SET "V_1=!V_X!" & SET "T_X=!TIME!" & FOR /F "tokens=1-4 delims=:." %%d in ("!T_X!") do (SET /A V_X=%%d*360000+1%%e*6000+1%%f*100+1%%g-610100) & SET /A DELAY=(!V_X!-!V_1!) & ECHO !T_X! - !T_1! = !DELAY!0 mSec!T_Str!"
SETLOCAL EnableDelayedExpansion
ECHO This measures the number of 10 mSec ticks during an interval
ECHO from either a %%TICK%% or a %%TOCK%% until a subsequent %%TOCK%%.
ECHO( & ECHO %%TICK%% makes no report, it only captures the 10 mSec clock reading
ECHO %%TOCK%% reports delay since previous clock reading and takes a new clock reading,
ECHO and appends %%T_Str%% or any text following %%TOCK%% - e.g. as "Cause of Delay/etc".
ECHO( & ECHO On my system %%TOCK%% takes about 1.5 mSec, 10 times faster than CALL code
ECHO(
%TICK%
SET "ANS=" & SET /P ANS= "Please Enter a NEW Name : "
rem SET "ANS=" & SET /P ANS= "Please Enter a Name : "
SET "T_Str= Your time entering the Name %ANS%"
%TOCK%
REN SET.TXT SET%ANS%.TXT
SET "T_Str= Code time Renaming SET.TXT to SET%ANS%.TXT
%TOCK%
ECHO --------------- Now do 50 Off invocations of %%TOCK%% ----------
SETLOCAL
SET "T_Str= ."
%TOCK% & %TOCK% & %TOCK% & %TOCK% & %TOCK% & %TOCK% & %TOCK% & %TOCK% & %TOCK% & %TOCK%
%TOCK% & %TOCK% & %TOCK% & %TOCK% & %TOCK% & %TOCK% & %TOCK% & %TOCK% & %TOCK% & %TOCK%
%TOCK% & %TOCK% & %TOCK% & %TOCK% & %TOCK% & %TOCK% & %TOCK% & %TOCK% & %TOCK% & %TOCK%
%TOCK% & %TOCK% & %TOCK% & %TOCK% & %TOCK% & %TOCK% & %TOCK% & %TOCK% & %TOCK% & %TOCK%
%TOCK% & %TOCK% & %TOCK% & %TOCK% & %TOCK% & %TOCK% & %TOCK% & %TOCK% & %TOCK% & %TOCK%
ENDLOCAL
ECHO --------------- 50 Off invocations of %%TOCK%% Now done --------
SET "T_Str= = 50 OFF %%TOCK%%
%TOCK% = Time Measurements
PAUSE
As previously, my special START code includes this - now on line 6
Code:
START "" /LOW /WAIT %0 :PROC
I observe no difference in speed if I remove the option switch /LOW
You may find a difference on your machine - especially if it is single core and busy on other things as well.
The very first time I ran my code I quickly regretted that I had not thought to use /LOW
My first code was flawed and START at normal priority launched the second instance and that concluded by doing what was hoped for,
BUT - before it did what it should have done it STARTed another instance,
and my system ran away from me with an exponential increase in the number of simultaneous instances of my code - recursion on steroids.
Very occasionally I could use TaskManager to select an instance of CMD.EXE and click the CLOSE button,
and I caught a glimpse of a CONFIRM prompt,
but several more instance of my code were concealing the prompt and taking focus before I could respond.
The madness stopped a minute or so later when all my 8 GB of RAM had been used up at 1 MB per instance,
and absolutely nothing worked anymore - apart from the front panel Power switch.
I had fears that I would need my Boot recover CD to restore my partition image,
but I am pleased to say the system powered up with the only abnormality that it noted a shutdown failure and offered start-up alternatives,
but normal start-up was free of incident.
As a kindness to others and for your safety in case you choose to experiment and make a similar booboo, I chose to retain /LOW
Regards
Alan