Why is the TEE command 120 times slower?

Oct 20, 2017
31
0
Netherlands
I have written this code:
Code:
@ECHO OFF
TIMER /1 ON
DO i in /S *.*
    ECHO %i
    ECHO %_date %_time %i >> %tmp\logbook1.txt
ENDDO
TIMER /1 OFF

It executes in 1 minute and 17 seconds.

Because ECHO is used twice, I have written this code:

Code:
@ECHO OFF
TIMER /1 ON
DO i in /S *.*
    ECHO %i | TEE /a /d /t  %tmp\logbook2.txt
ENDDO
TIMER /1 OFF

It executes in 2 hours 45 minutes and 11 seconds.

Question: why is the TEE command 120 times slower?
 
Apr 18, 2014
301
9
I suspect it's because every time you use the pipe a new instance of TCC is started which carries a processing overhead. Do you have

Code:
iff %_pipe EQ 1 then...

in your TCCstart to ensure only the necessary parts of the startup files is processed in a pipe?

If you haven't already, you might wish to review the TCC help for In process pipes, they might be quicker in this case.
 

rconn

Administrator
Staff member
May 14, 2008
12,404
152
Redirection just changes the output handle to point to a file instead of the console. A pipe starts a second copy of TCC and connects the output of the parent with the input of the child. So you're starting a new TCC every time through the DO loop.

You should be using a command group and piping that, or piping the output of the entire batch file.
 
May 20, 2008
11,536
103
Syracuse, NY, USA
I suspect it's because every time you use the pipe a new instance of TCC is started which carries a processing overhead. Do you have

Code:
iff %_pipe EQ 1 then...

in your TCCstart to ensure only the necessary parts of the startup files is processed in a pipe?

If you haven't already, you might wish to review the TCC help for In process pipes, they might be quicker in this case.
The first line of my TCSTART.BTM is
Code:
if %_pipe == 1 .or. %_transient == 1 quit

Here, the time difference between dumbenis's two experiments is a factor of 10. I suppose the loading/saving of a history file (which I don't do) could also make a significant difference.
 
May 20, 2008
11,536
103
Syracuse, NY, USA
You should be using a command group and piping that, or piping the output of the entire batch file.
Amen!

Here, this
Code:
TIMER /1 ON
DO i in /S *.* | TEE /a /d /t %tmp\logbook2.txt
    ECHO %i
ENDDO
TIMER /1 OFF

is about 3 times as fast as
Code:
TIMER /1 ON
DO i in /S *.*
    ECHO %_date %_time %i
    ECHO %_date %_time %i >> %tmp\logbook1.txt
ENDDO
TIMER /1 OFF
 
May 20, 2008
11,536
103
Syracuse, NY, USA
The construction's behavior ain't very clear, I must say.
If you mean
[/code]
DO i in /S . | TEE /a /d /t %tmp\logbook2.txt
ECHO %i
ENDDO[/code]
I agree. But I don't know another way to do it with a multi-line DO without a subroutine or another batch file. Fortunately, it works. I'm not crazy about the way this (below) looks, but it also works.
Code:
TIMER /1 ON
GOSUB doit | TEE /a /d /t %tmp\logbook2.txt 
TIMER /1 OFF
QUIT

:doit
DO i in /S *.*
    ECHO %i
ENDDO
RETURN
 
Aug 23, 2010
647
9
Yes, I mean redirection in the first line.
In all other shells, the redirection normally placed at the end of structural block.
 
Nov 18, 2009
22
0
Redirection just changes the output handle to point to a file instead of the console. A pipe starts a second copy of TCC and connects the output of the parent with the input of the child. So you're starting a new TCC every time through the DO loop.

You should be using a command group and piping that, or piping the output of the entire batch file.

Perhaps TCC could handle the "| TEE" construct specially ?
 

rconn

Administrator
Staff member
May 14, 2008
12,404
152
Perhaps TCC could handle the "| TEE" construct specially ?

Three problems with that:

1) At the time of the redirection, TCC doesn't know (or care) what the next command is going to be. That would require a major effort to write a new "look ahead" parser.

2) I think it's a bad idea in general to change the behavior based on isolated cases. It tends to surprise the users, usually unpleasantly.

3) Changing the pipe behavior when it's going to a TEE would actually slow down the output if you are using the appropriate syntax for piping -- i.e., with a command group or piping the batch file output.
 
Similar threads
Thread starter Title Forum Replies Date
old coot tee command cancels colors Support 33
C TEE command appending null characters to output Support 6
David McClelland TEE command puts it's output file in c:\ Support 4
A How to? TEE - duplicate output to STDERR Support 3
Peter Murschall TEE cannot handle Unicode output Support 2
vefatica TEE /A adds newline? Support 2
vefatica Debug messages from TEE? Support 3
Joe Caverly Problem with TEE in v22 Support 2
Roedy problem with tee Support 2
krischik WAD Tee printing Chinese characters Support 7
J TEE Problem Support 11
vefatica WAD TEE adds newlines Support 4
A How to? Use TEE with .NET output Support 6
D WAD Multiple TEE causese weird variable scoping? Support 7
S Tee? Support 9
Z CMDDebug - TCC unknown command Support 2
F Edit command Support 1
rconn News Take Command / TCC / CMDebug / TCC-RT 28.02.17 Support 0
old coot LEAVE appears to affect command-line arguments Support 11
J VDESKTOP command Support 3
Dmitry L. Kobyakov How to? How to remove the record of the old version of the Take Command? Support 9
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) [SOLVED] Support 1
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

Similar threads