Welcome!

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

SignUp Now!

BTM slower than BAT?

Jul
12
0
Having been a user of tcc in it's various manifestations since 4dos days, I was a believer in the "BTM files are faster than BAT files" mantra.
But a few nagging doubts led me to test TT.BAT, a script of 5000+ lines.

I ran this with two tcc versions:
TCC 23.00.25 x64 Windows 10 [Version 10.0.17763.557]
TCC 17.00.77 x64 Windows 8.1 [Version 6.3.17763]
(both are actually on the same Windows 10 machine)

I ran each version in two modes:
loadbtm OFF
loadbtm ON

With the results, sorted by elapsed time:
loadbtm OFF TCC 23 Timer 1 off: 06:06:10 Elapsed: 0:00:01,73
loadbtm OFF TCC 17 Timer 1 off: 06:30:26 Elapsed: 0:00:07,30
loadbtm ON TCC 23 Timer 1 off: 05:44:20 Elapsed: 0:00:17,43
loadbtm ON TCC 17 Timer 1 off: 06:33:29 Elapsed: 0:00:32,34
TCC 23 is impressively faster than 17, but dwarfed by the loadbtm anomaly.

Addition testing showed:
1. In the absence of an explicit loadbtm, the file suffix (.BAT or .BTM) is the deciding factor.
2. Commands taking the most time are:
gosub
iff islabel ...

Since these results appear to contradict any documentation I could find, such as:
TCC > Commands > LOADBTM
google for: BTM "slower" than BAT site:jpsoft.com
the chances should be high that I have made some mistake, such as not knowing the difference between OFF and ON.
I therefore await a compassionate explanation, or vindication, with equal interest.
 
There isn't much point in LOADBTM any more. 25 years ago, disk read/writes were not buffered very well, and a LOADBTM ON could make a big difference (though not as much as simply naming the file with a .BTM extension). Current disk drives make the difference pretty minimal.

However, running the same file as a .CMD versus a .BTM shouldn't make a difference, as the command parser is exactly the same. I would need to see your batch file to see what's happening - certainly if you do LOADBTM OFF / ON more than once (or worse, in a loop) you'll see a significant performance penalty.
 
There isn't much point in LOADBTM any more. 25 years ago, disk read/writes were not buffered very well, and a LOADBTM ON could make a big difference (though not as much as simply naming the file with a .BTM extension). Current disk drives make the difference pretty minimal.

LOADBTM ON does still make a dramatic difference for remote files — login scripts, e.g.
 
Indeed LOADBTM is irrelevant (in this particular case).
I've attached a dummy TT.BAT that illustrates the timing difference.
The script in its entirety is:

@echo off
setlocal
timer ON
set COUNT=9
do N = 1 to %[COUNT]
if islabel NO_SUCH_LABEL echo never
enddo
timer OFF
echo %[_batchname] done
quit 0

The rest is just filler.

I ran the commands:

copy tt.bat tt.btm

tt.bat
Timer 1 on: 17:24:00
Timer 1 off: 17:24:01 Elapsed: 0:00:01,37
T:\t\tt.bat done

tt.btm
Timer 1 on: 17:24:08
Timer 1 off: 17:24:37 Elapsed: 0:00:28,61
T:\t\tt.btm done
 

Attachments

  • tt.bat
    486 KB · Views: 285
Compare:
Code:
v:\> ver

TCC  16.03.55   Windows 7 [Version 6.1.7601]

v:\> tt.bat
Timer 1 on: 13:12:50
Timer 1 off: 13:13:10  Elapsed: 0:00:19.89
V:\tt.bat done

v:\> tt.btm
Timer 1 on: 13:13:17
Timer 1 off: 13:13:18  Elapsed: 0:00:01.59
V:\tt.btm done

Code:
v:\> ver

TCC  17.00.77   Windows 7 [Version 6.1.7601]

v:\> tt.bat
Timer 1 on: 13:14:07
Timer 1 off: 13:14:10  Elapsed: 0:00:02.96
V:\tt.bat done

v:\> tt.btm
Timer 1 on: 13:14:12
Timer 1 off: 13:14:36  Elapsed: 0:00:23.20
V:\tt.btm done
 
Your batch file isn't measuring LOADBTM or the processing speed of BAT vs. BTM, it's measuring how long it takes to read a 500K file line by line and save it to memory, versus how long it takes to not do that. Not doing that is always going to win!

Since your batch file is only executing a small fraction of the contents of the file, you're comparing reading & executing maybe 1K of a BAT file, versus reading 500K of a BTM and then executing 1K of it. BTM will win by a small amount in the execution time; BAT is going to win by loading 1K vs. 500K.
 
I can't see how "BAT is going to win by loading 1K" when BAT must surely also load 500K to execute the statement

if islabel NO_SUCH_LABEL echo never
 
Since your batch file is only executing a small fraction of the contents of the file, you're comparing reading & executing maybe 1K of a BAT file, versus reading 500K of a BTM and then executing 1K of it. BTM will win by a small amount in the execution time; BAT is going to win by loading 1K vs. 500K.
Can you explain that further? I don't get it.

Why the v16-v17 difference?

And it doesn't seem to matter if the "extra" stuff is executed or not. I tested with a lot of "noop foo" statements (using a do-nothing plugin) or a lot of "echo > NUL" statements. If there's enough of them the BAT wins in versions > 16. And the more there are, the greater the advantage to the BAT.
 
I can't see how "BAT is going to win by loading 1K" when BAT must surely also load 500K to execute the statement

if islabel NO_SUCH_LABEL echo never
Well, not exactly. That BAT only has to read every line, not (also) store it in memory.
 
V17 eliminated the line length (and variable length) restrictions by going to string classes instead of character arrays.
I still don't get it. Is searching through the in-memory instances of a string class slower that searching through the file?
 
I find the significant fact is that executing
IF ISLABEL ...
just 9 times takes some 27 seconds longer in a BTM file than a BAT file.
The BTM script should read 5000 lines once and store them in memory which is searched 9 times. This takes 28.6 seconds.
The BAT script should read and search 5000 lines from the disk file 9 times. This takes 1.4 seconds.
My feeling is that differences such as storing in memory and string classes versus character arrays pale into insignificance with these timings.
 
Earlier I posted a comparison between v16 and v17. Here's a comparison between v16 and v24 (with similar results). We have talked (I guess) about why the BTM was so much slower in v24. But why is the BAT so much faster in v24 (compared to the BAT in v16)?

Code:
v:\> echo %@compare[tt.bat,tt.btm]
1

v:\> do v in /L 16 24 ( g:\tc%v\tcc /c "ver & tt.bat & tt.btm" )

TCC  16.03.55   Windows 7 [Version 6.1.7601]
Timer 1 off: 11:19:04  Elapsed: 0:00:15.90
V:\tt.bat done (N = 10)
Timer 1 off: 11:19:04  Elapsed: 0:00:00.47
V:\tt.btm done (N = 10)

TCC  24.02.49   Windows 7 [Version 6.1.7601]
Timer 1 off: 11:19:05  Elapsed: 0:00:00.70
V:\tt.bat done (N = 10)
Timer 1 off: 11:19:25  Elapsed: 0:00:20.39
V:\tt.btm done (N = 10)
 
... But why is the BAT so much faster in v24 (compared to the BAT in v16)?
I was tempted, in the absence of more informed opinion, to wonder if the BAT / BTM test had been accidentally inverted since v17 ;)
Rather more scientifically, I used procmon.exe to monitor the tcc.exe process, see attached tt4.zip content.
I simplified the script tt4.bat / btm (timings on v23 remained consistent with earlier results):
Code:
@echo off
timer ON >nul:
if islabel NO_SUCH_LABEL echo never
if islabel NO_SUCH_LABEL echo never
if islabel NO_SUCH_LABEL echo never
if islabel NO_SUCH_LABEL echo never
timer OFF
echo %[_batchname] : done
quit 0
Steps taken:
- reset procmon filters
- apply filter for the tcc.exe process
- clear event log
- run tt4.bat
- save event log to tt4.bat.csv
- clear event log
- run tt4.btm
- save event log to tt4.btm.csv
The 61 lines of tt4.btm.csv show no external activity during the 13 seconds after closing the file:
Code:
"04:43:41,6887098","tcc.exe","6600","ReadFile","C:\t\tt4.btm","SUCCESS","Offset: 0, Length: 497.727"
"04:43:41,6888852","tcc.exe","6600","CloseFile","C:\t\tt4.btm","SUCCESS",""
"04:43:54,9932064","tcc.exe","6600","CreateFile","C:\t","SUCCESS","Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a, OpenResult: Opened"
The 46.173 lines of tt4.bat.csv confirm that the entire file is read repetitively, line by line.
 

Attachments

  • tt4.zip
    416.3 KB · Views: 270

Similar threads

Back
Top