Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Why is the same command so much faster in a BTM?

May
13,829
211
Code:
v:\> type timertest.btm
do i=1 to 10 (timer /1 /q on & echo %@timer[1,us])

These results are typical.

Code:
v:\> do i=1 to 10 (timer /1 /q on & echo %@timer[1,us])
176 us
108 us
106 us
107 us
105 us
104 us
104 us
104 us
104 us
104 us

v:\> timertest.btm
149 us
65 us
64 us
64 us
63 us
63 us
64 us
63 us
63 us
65 us
 
I thought that I had a fast computer, but my times are much longer than yours, and the difference is much greater. It does seem weird that a batch file would run so much faster. I'm eager to hear an explanation from Rex.

Code:
[TCC34.01.27 | C:\temp]
>do i=1 to 10 (timer /1 /q on & echo %@timer[1,us])
678 us
609 us
594 us
612 us
608 us
1423 us
633 us
612 us
607 us
588 us

[TCC34.01.27 | C:\temp]
>echo `do i=1 to 10 (timer /1 /q on & echo %@timer[1,us])` > test.btm

[TCC34.01.27 | C:\temp]
>test.btm
177 us
173 us
172 us
172 us
172 us
198 us
172 us
171 us
172 us
172 us
 
My computer's speed is 3.5 Ghz and it runs close to a minimum of processes, typically 90-95.
 
My computer's speed is rated at 3.8 GHz with 12 cores and 24 threads (and most of the cores are actually running at 4.2 GHz). It is quite likely that I have a lot of processes running. Is there an easy way to count them?

I just tried running the same command as an alias, and that seems (not surprisingly) to be essentially the same as running it from the command line. Running the batch script with a multi-line DO seems (again not surprisingly) to be essentially the same as running the single-line DO from a script.
 
Is there an easy way to count them?
I have a few plugins that do it. One way (there might be a better one) would be count the output lines of tasklist /nf. If you're using an external and/or a pipe to do that you might get one or two extra.
 
You probably have batch echoing turned off. Turn that back on and you'll see less difference.

The parser does a number of things when it's at the command prompt that it doesn't do when running a batch file. My question for you is -- why do you care?
The results are the same with ECHO ON at the beginning of the BTM.

Because I'm surprized, curious, and obsessed with timing things.

This is done 10 times: (timer /1 /q on & echo %@timer[1,us])

The only things that will affect the result the things which happen after TIMER returns and before @TIMER is expanded.
 
I doubt you really want to know the hundreds of things the parser is doing to your command line before it passes it on to the command to execute. Suffice to say - a lot.
None of that is being timed.
 
It is all being timed, when you run DO from the command line.
I don't know what you're talking about. Here's the command. What is it timing?

(timer /1 /q on & echo %@timer[1,us])
 
Much more and seemingly random variance here:
[C:\Program Files\JPSoft\TCMD34]do i=1 to 10 (timer /1 /q on & echo %@timer[1,us])​
154 us​
81 us​
81 us​
78 us​
79 us​
78 us​
79 us​
85 us​
79 us​
79 us​
[C:\Program Files\JPSoft\TCMD34]do i=1 to 10 (timer /1 /q on & echo %@timer[1,us])​
87 us​
80 us​
80 us​
79 us​
83 us​
98 us​
267 us​
81 us​
119 us​
240 us​
[C:\Program Files\JPSoft\TCMD34]do i=1 to 10 (timer /1 /q on & echo %@timer[1,us])​
533 us​
272 us​
78 us​
78 us​
87 us​
267 us​
144 us​
81 us​
85 us​
82 us​
 
Back
Top