Here's the fast one (it took me a few days to create the macro on one line like you did; I'm going crazy.)
Code: Select all
:: make sure we are in the spotlight:
:: run as administrator for realtime priority!!!
:: /affinity 0x3 = 2 core/thread
@if "%~1"=="" start /realtime conhost "%~f0" 1&exit /b
@echo off & setlocal DisableDelayedExpansion
:: 8190
set str1=^
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx^
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx^
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx^
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx^
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx^
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx^
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx^
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx^
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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xxxxxxxxxxxxxxxxxxxxxxxx^
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx^
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx^
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxX
:: 6000
set "str2=%str1:~,6000%"
:: 4000
set "str3=%str1:~,4000%"
:: 2000
set "str4=%str1:~,2000%"
:: 1000
set "str5=%str1:~,1000%"
:: 200
set "str6=%str1:~,200%"
:: 10
set "str7=%str1:~,10%"
call :initTimediff
:: uncomment this to get the evidence that it also works with delayed expansion enabled
::setlocal EnableDelayedExpansion
echo(
echo ~~~~~~~~~~~~~~~~~~~~
echo Steffen
call :initStrLenSteffen
echo Functional test
call :func_test
rem call :test str1
rem call :test str2
rem call :test str3
rem call :test str4
rem call :test str5
rem call :test str6
rem call :test str7
echo(
echo ~~~~~~~~~~~~~~~~~~~~
echo Francesco
call :initStrLenFrancesco
echo Functional test
call :func_test
rem call :test str1
rem call :test str2
rem call :test str3
rem call :test str4
rem call :test str5
rem call :test str6
rem call :test str7
echo(
echo ~~~~~~~~~~~~~~~~~~~~
echo jeb
echo Functional test
call :func_test
rem call :test str1
rem call :test str2
rem call :test str3
rem call :test str4
rem call :test str5
rem call :test str6
rem call :test str7
echo(
echo ~~~~~~~~~~~~~~~~~~~~
echo final
call :initStrLen
echo Functional test
call :func_test
call :test str1
call :test str2
call :test str3
call :test str4
call :test str5
call :test str6
call :test str7
echo(
echo ~~~~~~~~~~~~~~~~~~~~
echo final 2
call :initStrLen2
echo Functional test
call :func_test
call :test str1
call :test str2
call :test str3
call :test str4
call :test str5
call :test str6
call :test str7
pause
exit /b
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:initStrLenSteffen
setlocal DisableDelayedExpansion
:: Computes the number of bytes in a string.
:: %strLen% str len
:: str - [ByRef In] Name of the variable containing the string to be measured.
:: len - [ByRef Out] Name of the variable that receives the measured length.
:: Strings of up to 8191 characters are supported.
set strLen=for %%- in (1 2) do if %%-==2 (^
setlocal EnableDelayedExpansion^&for /f "tokens=1,2" %%. in ("^^!`^^!") do ^
set #=0^&(if defined %%~. (if ` neq ^^!%%~.:~4095^^!` ^
(set $=^^!%%~.:~4096^^!F^&set /a #+=4096) else set $=^^!%%~.^^!F)^&^
(for %%# in (2048 1024 512 256) do if ` neq ^^!$:~%%#^^!` ^
set $=^^!$:~%%#^^!^&set /a #+=%%#)^&set $=^^!$^^!^
EDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210^
FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210^
FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210^
FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210^
FFFFFFFFFFFFFFFFEEEEEEEEEEEEEEEEDDDDDDDDDDDDDDDDCCCCCCCCCCCCCCCC^
BBBBBBBBBBBBBBBBAAAAAAAAAAAAAAAA99999999999999998888888888888888^
7777777777777777666666666666666655555555555555554444444444444444^
333333333333333322222222222222221111111111111111^&^
set /a #+=0x^^!$:~511,1^^!^^!$:~255,1^^!)^&^
for %%# in (^^!#^^!) do endlocal^&set %%~/=%%#) else set `=
endlocal&set "strLen=%strLen%"
if !!# neq # set "strLen=%strLen:^^=%"
goto :eof
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:initStrLenFrancesco
setlocal DisableDelayedExpansion
set strLen=for %%- in (1 2) do if %%-==2 (^
setlocal EnableDelayedExpansion^&for /f "tokens=1,2" %%. in ("^^!`^^!") do ^
set #=0^&(if defined %%~. (if ` neq ^^!%%~.:~4095^^!` ^
(set $=^^!%%~.:~4096^^!^&set #=4096) else set $=^^!%%~.^^!)^&^
(if defined $ if "^^!$:~255,1^^!" neq "" ^
set "t=^^!$:~3839,1^^!^^!$:~3583,1^^!^^!$:~3327,1^^!^^!$:~3071,1^^!^^!$:~2815,1^^!^^!$:~2559,1^^!^^!$:~2303,1^^!^^!$:~2047,1^^!^^!$:~1791,1^^!^^!$:~1535,1^^!^^!$:~1279,1^^!^^!$:~1023,1^^!^^!$:~767,1^^!^^!$:~511,1^^!^^!$:~255,1^^!FEDCBA9876543210"^&^
set /a "#+=t=0x^^!t:~15,1^^!*256"^&for %%# in (^^!t^^!) do set "$=^^!$:~%%#^^!")^&^
if defined $ ^
set "t=^^!$:~239,1^^!^^!$:~223,1^^!^^!$:~207,1^^!^^!$:~191,1^^!^^!$:~175,1^^!^^!$:~159,1^^!^^!$:~143,1^^!^^!$:~127,1^^!^^!$:~111,1^^!^^^!$:~95,1^^!^^!$:~79,1^^!^^!$:~63,1^^!^^!$:~47,1^^!^^!$:~31,1^^!^^!$:~15,1^^!FEDCBA9876543210"^&^
set /a "t=0x^^!t:~15,1^^!*16"^&for %%# in (^^!t^^!) do ^
set "$=^^!$:~%%#^^!FEDCBA9876543210"^&set /a "#+=t+0x^^!$:~15,1^^!")^&^
for %%# in (^^!#^^!) do endlocal^&set %%~/=%%#) else set `=
endlocal&set "strLen=%strLen%"
if !!# neq # set "strLen=%strLen:^^=%"
goto :eof
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:initStrLenJeb
::: Macro to define macros without knowing the delayed expansion mode
::: Usage:
::: %$lib.macrodefine.free% set my_macro=...
:::
::: Reserved FOR variables:
::: %%! - contains one !
::: %%^ - results into one caret, attention read the other comments!
:::
::: While defining a new macro:
::: - Each bang ! has to be changed to %%! regex-replace: (?<!%%)! -> %%!
::: - Each caret ^ has to be changed to %%^^ regex-replace: (?<!%%)\^ -> %%^^
::: - If carets are inside quotes replace them only with %%^ .
::: - But be careful only replace carets that should be placed in the macro itself
::: - Carets can also be used for escaping special chars in the definition phase, like ^&, ^<, ^|, ^"
FOR /F "tokens=1 delims== " %%! in ("!=! ^^^!") DO ^
FOR /F %%^^ in ("^ ^^^^%%!=%%!") DO ^
set ^"$lib.macrodefine.free=@FOR /F "tokens=1 delims== " %%%%! in ("%%!=%%! %%^%%^%%^%%!") DO ^
@FOR /F %%%%^^%%^^ in ("%%^ %%^%%^%%^%%^%%^%%!=%%^%%!") DO @"
REM *** Defining a line feed for usage while defining macros
(set ^"$\n=^^^
%=empty=%
)
@REM %$lib.macrodefine.free% echo "Test1: %%! and %%^ --"
@REM %$lib.macrodefine.free% echo Test2: %%! and %%^^ --
:: Computes the number of bytes in a string.
:: %strLen% str len
:: str - [ByRef In] Name of the variable containing the string to be measured.
:: len - [ByRef Out] Name of the variable that receives the measured length.
:: Strings of up to 8191 characters are supported.
%$lib.macrodefine.free% set strLen=for %%# in (1 2) do if %%#==2 ( %$\n%
for /f "tokens=1,2" %%1 in ("%%!args%%!") do ( %$\n%
set L=0 %$\n%
if defined %%~1 ( %$\n%
if "" neq "%%!%%~1:~255%%!" ( %$\n%
for %%# in (4095 2047 1023 511 255) do ( %$\n%
set /a t=L+%%# %$\n%
for %%T in (%%!t%%!) do ( %$\n%
if "" neq "%%!%%~1:~%%T%%!" set /a L=%%T+1 %$\n%
) %$\n%
) %$\n%
) %$\n%
for %%# in (%%!L%%!) do ( %$\n%
set ^"$=%%!%%~1:~%%#%%!^
FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210^
FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210^
FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210^
FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210^
FFFFFFFFFFFFFFFFEEEEEEEEEEEEEEEEDDDDDDDDDDDDDDDDCCCCCCCCCCCCCCCC^
BBBBBBBBBBBBBBBBAAAAAAAAAAAAAAAA99999999999999998888888888888888^
7777777777777777666666666666666655555555555555554444444444444444^
333333333333333322222222222222221111111111111111^" %$\n%
set /a L+=0x%%!$:~511,1%%!%%!$:~255,1%%! %$\n%
) %$\n%
) %$\n%
for %%# in (%%!L%%!) do ( %$\n%
endlocal %$\n%
set %%~2=%%# %$\n%
) %$\n%
) %$\n%
) else setlocal EnableDelayedExpansion ^& set args=
goto :eof
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:initStrLen Final
:: Computes the number of bytes in a string.
:: %strLen% str len
:: str - [ByRef In] Name of the variable containing the string to be measured.
:: len - [ByRef Out] Name of the variable that receives the measured length.
:: Strings of up to 8191 characters are supported.
FOR /F %%! IN ("! ^! ^^^!") DO ^
set strLen=^
for /f "tokens=2" %%? in ("%%!%%! D E") do for %%. in (1 2) do if %%.==2 (^
for /f "tokens=1,2" %%1 in ("%%!$args%%!") do (^
set "$L=0"^&^
(if defined %%~1^
(if "" neq "%%!%%~1:~255%%!"^
(if "" neq "%%!%%~1:~4095%%!"^
(set "$=%%!%%~1:~4096%%!"^&set "$L=4096") else set "$=%%!%%~1%%!"^
)^&^
(if defined $^
set ^"$scale=^
%%!$:~255,1%%!%%!$:~511,1%%!%%!$:~767,1%%!%%!$:~1023,1%%!%%!$:~1279,1%%!^
%%!$:~1535,1%%!%%!$:~1791,1%%!%%!$:~2047,1%%!%%!$:~2303,1%%!%%!$:~2559,1%%!^
%%!$:~2815,1%%!%%!$:~3071,1%%!%%!$:~3327,1%%!%%!$:~3583,1%%!%%!$:~3839,1%%!^
FEDCBA9876543210^"^&^
set /a "$L+=0x%%!$scale:~15,1%%!*256"^
)^
)^&^
for %%# in (%%!$L%%!) do set ^"$=%%!%%~1:~%%#%%!^
FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210^
FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210^
FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210^
FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210^
FFFFFFFFFFFFFFFFEEEEEEEEEEEEEEEEDDDDDDDDDDDDDDDDCCCCCCCCCCCCCCCC^
BBBBBBBBBBBBBBBBAAAAAAAAAAAAAAAA99999999999999998888888888888888^
7777777777777777666666666666666655555555555555554444444444444444^
333333333333333322222222222222221111111111111111^"^&^
set /a "$L+=0x%%!$:~511,1%%!%%!$:~255,1%%!"^
)^&^
for %%# in (%%!$L%%!) do (if %%?==D endlocal)^&set "%%~2=%%#"^
)^
) else (if %%?==D setlocal EnableDelayedExpansion)^&set $args=
goto :eof
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:initStrLen2 final 2
:: Computes the number of bytes in a string.
:: %strLen% str len
:: str - [ByRef In] Name of the variable containing the string to be measured.
:: len - [ByRef Out] Name of the variable that receives the measured length.
:: Strings of up to 8191 characters are supported.
FOR /F %%! IN ("! ^! ^^^!") DO ^
set strLen=^
for /f "tokens=2" %%? in ("%%!%%! D E") do for %%. in (1 2) do if %%.==2 (^
for /f "tokens=1,2" %%1 in ("%%!$args%%!") do (^
if defined %%~1 ^
((if "" neq "%%!%%~1:~255%%!"^
(^
(if "" neq "%%!%%~1:~4095%%!"^
(set "$=%%!%%~1:~4095%%!") else set "$=%%!%%~1%%!"^
)^&^
set ^"$scale=^
%%!$:~255,1%%!%%!$:~511,1%%!%%!$:~767,1%%!%%!$:~1023,1%%!%%!$:~1279,1%%!^
%%!$:~1535,1%%!%%!$:~1791,1%%!%%!$:~2047,1%%!%%!$:~2303,1%%!%%!$:~2559,1%%!^
%%!$:~2815,1%%!%%!$:~3071,1%%!%%!$:~3327,1%%!%%!$:~3583,1%%!%%!$:~3839,1%%!^
FEDCBA9876543210^"^&^
(^
if "" neq "!%%~1:~4095!" ( set /a "$L=0x!$scale:~15,1!*256+4095") else set /a "$L=0x%%!$scale:~15,1%%!*256"^
)^
) else set "$L=0"^
)^&^
for %%# in (%%!$L%%!) do set ^"$=%%!%%~1:~%%#%%!^
FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210^
FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210^
FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210^
FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210^
FFFFFFFFFFFFFFFFEEEEEEEEEEEEEEEEDDDDDDDDDDDDDDDDCCCCCCCCCCCCCCCC^
BBBBBBBBBBBBBBBBAAAAAAAAAAAAAAAA99999999999999998888888888888888^
7777777777777777666666666666666655555555555555554444444444444444^
333333333333333322222222222222221111111111111111^"^&^
for %%# in ("%%!$L%%!+0x%%!$:~511,1%%!%%!$:~255,1%%!") do (if %%?==D endlocal)^&set /A "%%~2=%%#"^
) else (if %%?==D endlocal)^&set "%%~2=0"^
)^
) else (if %%?==D setlocal EnableDelayedExpansion)^&set $args=
goto :eof
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:initTimediff
for /f %%! in ("! ^! ^^^!") do ^
set timediff=for /l %%# in (1 1 2) do if %%#==2 for /f "tokens=2" %%$ in ("%%!%%! 1 0") do ((if 1==%%$ setlocal EnableDelayedExpansion)^&for /f "tokens=1-3" %%- in ("%%!_i_%%!") do (set "_t1_=%%!%%~-: =0%%!"^&set "_t2_=%%!%%~.: =0%%!"^&^
set /a "_d_=(8640000+(((1%%!_t2_:~,2%%!*60+1%%!_t2_:~3,2%%!)*60+1%%!_t2_:~6,2%%!)*100+1%%!_t2_:~-2%%!-36610100)-(((1%%!_t1_:~,2%%!*60+1%%!_t1_:~3,2%%!)*60+1%%!_t1_:~6,2%%!)*100+1%%!_t1_:~-2%%!-36610100))%%8640000,_o_=100000000+(_d_%%100),_d_/=100,_o_+=(_d_%%60)*100,_d_/=60,_o_+=(_d_%%60)*10000+_d_/60*1000000"^&^
set "_o_=%%!_o_:~1,2%%!:%%!_o_:~3,2%%!:%%!_o_:~5,2%%!.%%!_o_:~-2%%!"^&for /f %%' in ("%%!_o_%%!") do ((if 1==%%$ endlocal)^&if "%%~/"=="" (echo %%') else set "%%~/=%%'"))) else set _i_=
goto :eof
:test
echo(
setlocal EnableDelayedExpansion
set len=
for /l %%i in (1 1 4) do (
set t1=!time!
for /l %%i in (1 1 5000) do %strLen% %1 len
set t2=!time!
%timediff% t1 t2 diff
echo !diff!
)
echo Check: len=!len!
endlocal
goto :eof
:::::::::::::::::::::::::::::::::::::::::::::::::...
:func_test
setlocal EnableDelayedExpansion
set "str="
for /L %%L in (0,1,8185) do (
%strLen% str len
set "str=!str!X"
title %%L !len!
if !len! neq %%L pause
)
goto :eof
Code: Select all
~~~~~~~~~~~~~~~~~~~~
final
Functional test
OK.
00:00:04.46
00:00:04.51
00:00:04.51
00:00:04.52
Check: len=8190
00:00:04.12
00:00:04.18
00:00:04.17
00:00:04.27
Check: len=6000
00:00:03.89
00:00:03.95
00:00:03.95
00:00:03.95
Check: len=4500
00:00:03.82
00:00:04.00
00:00:04.06
00:00:03.89
Check: len=2000
00:00:03.73
00:00:03.76
00:00:03.76
00:00:03.75
Check: len=1000
00:00:02.63
00:00:02.68
00:00:02.68
00:00:02.68
Check: len=200
00:00:02.60
00:00:02.68
00:00:02.68
00:00:02.67
Check: len=10
~~~~~~~~~~~~~~~~~~~~
final 2
Functional test
OK.
00:00:03.97
00:00:04.03
00:00:04.03
00:00:04.03
Check: len=8190
00:00:03.65
00:00:03.72
00:00:03.70
00:00:03.71
Check: len=6000
00:00:03.40
00:00:03.47
00:00:03.45
00:00:03.46
Check: len=4500
00:00:03.54
00:00:03.59
00:00:03.66
00:00:03.59
Check: len=2000
00:00:03.39
00:00:03.45
00:00:03.47
00:00:03.46
Check: len=1000
00:00:02.55
00:00:02.61
00:00:02.61
00:00:02.61
Check: len=200
00:00:02.55
00:00:02.60
00:00:02.60
00:00:02.60
Check: len=10
Premere un tasto per continuare . . .
Code: Select all
5000 cycles
:: | final | final2 |
::------+--------+---------+
:: 8190 | 04.51 | 04.03 |
:: 6000 | 04.17 | 03.71 |
:: 4500 | 03.95 | 03.46 |
:: 2000 | 04.00 | 03.60 |
:: 1000 | 03.76 | 03.46 |
:: 200 | 02.68 | 02.61 |
:: 10 | 02.68 | 02.60 |
Code: Select all
10000 cycles
:: | final | final2 |
::------+--------+---------+
:: 8190 | 09.02 | 08.06 |
:: 6000 | 08.27 | 07.40 |
:: 4500 | 07.81 | 06.95 |
:: 2000 | 07.70 | 07.21 |
:: 1000 | 07.40 | 06.94 |
:: 200 | 05.34 | 05.26 |
:: 10 | 05.31 | 05.24 |
I also wanted to ask you what difference there is between calling "cmd" or "conhost".