Why is the TEE command 120 times slower?

Oct 20, 2017
13
0
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
167
3
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
10,925
97
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
9,195
60
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
9,195
60
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
9,195
60
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
335
5
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
21
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 ?