batch file iterating sorted pairs slow -
i not using batch please forgive me if obvious. prefer not use make on 1 if have to. let's take if can fix instead:
it goes through (only) 137 .c's in folder compares modification-date .o's , recompiles if newer.
the inner for-loop name of newer file %%i
variable, should not have quadratic run-time, the problem is way slow. takes 10 seconds if nothing needs recompiling, looping , sorting each pair.
for %%f in (*.c) ( /f "delims=" %%i in ('dir /b /od %%~nf.o %%~nf.c ^| more +1') ( if %%i == %%~ni.c ( rem recompile file ) else ( rem skip ) ) )
but start 137 dir /b
rounds each each of 137 c-files.
, start new cmd context pipe.
i suppose it's not best way compare file times.
sort complete directory, should faster.
first sort c , o files date , create variable (cfile_<filename>
) each c-file.
, each o-file clear variable.
after files remaining cfile_
variables used recompile related c-files.
the redirection 2>nul
avoid error message case, when no variables begins cfile_
.
@echo off setlocal enabledelayedexpansion rem remove old variables /f "delims=" %%a in ('set cfile_ 2^>nul') set "%%a=" /f "delims=" %%i in ('dir /b /od *.o *.c') ( if %%~xi==.o ( set "cfile_%%~ni=" ) else ( set cfile_%%~ni=1 ) ) /f "tokens=2* delims=_" %%c in ('set cfile_ 2^>nul') echo recompile %%c
Comments
Post a Comment