- May
- 13,745
- 209
I'm testing a pair of plugin functions. The command VARNAMES outputs the names of the environment variables, one per line. The variable function @VARNAMES[] returns an =-separated list of the environment variable names. The two use nearly identical code, the only difference being
for VARNAMES, vs.
for @VARNAMES.
I'd expect them to be nearly equally fast. But they're not even close (see below). Each will accept a regular expression on which to match variable names but below, none is specified, so regex_match() is not called.
Rex, can you guess what accounts for the huge difference in times? I have no complaints; I'm just very curious.
Code:
if ( !bUseRegex || (rx = regex_match(szRegex, szVarName)) > 0 )
Printf(L"%s\r\n", szVarName);
Code:
if ( !bUseRegex || (rx = regex_match(szRegex, szVarName)) > 0 )
psz += Sprintf(psz, L"%s=", szVarName);
I'd expect them to be nearly equally fast. But they're not even close (see below). Each will accept a regular expression on which to match variable names but below, none is specified, so regex_match() is not called.
Code:
v:\> timer & for /l %i in (1,1,10000) (varnames > nul) & timer
Timer 1 on: 19:51:00
Timer 1 off: 19:51:14 Elapsed: 0:00:13.14
v:\> timer & for /l %i in (1,1,10000) (echo %@varnames[] > nul) & timer
Timer 1 on: 19:51:15
Timer 1 off: 19:51:18 Elapsed: 0:00:02.94