call vs pipe
Posted: 19 Apr 2016 08:46
I wonder if anybody else wondered if there's a point to use pipe instead of call (and eventually subroutine) as pipe can also be used for doubled expansion like call and can shortens some expression (e.g. if and for cannot be called but can be used with pipe).Unfortunately seems that pipe is around 6 times slower than calling subroutine (when the subroutine is close to the call).Probably because it creates new cmd processes on both sides of the pipe
.
So I suppose it's better to use subroutines than pipes (pretty simple test):
results on my machine:

So I suppose it's better to use subroutines than pipes (pretty simple test):
Code: Select all
@echo off
set a=1
echo %time%
(
for /l %%# in (1,1,1000) do (
set a=2
(break|echo %%a%%)>nul
)
)
echo %time%
(
for /l %%# in (1,1,1000) do (
set a=3
(call ::subr %%a%%)>nul
)
)
echo %time%
exit /b %errorlevel%
:subr
echo %1
results on my machine:
Code: Select all
17:36:43.63
17:36:50.35
17:36:51.32