This repository was archived by the owner on Aug 5, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark.bat
More file actions
62 lines (49 loc) · 1.97 KB
/
Copy pathbenchmark.bat
File metadata and controls
62 lines (49 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
@echo off
setlocal enabledelayedexpansion
rem Get test selection
set /p "testnum=Enter test number (1-4): "
if %testnum%==1 (
set "testfile=hello"
) else if %testnum%==2 (
set "testfile=labels"
) else if %testnum%==3 (
set "testfile=vars"
) else if %testnum%==4 (
set "testfile=invalid_command"
) else (
echo Invalid test number
exit /b 1
)
set /p "iter=Enter number of iterations: "
if "%iter%"=="" (
echo No iterations specified, defaulting to 10.
set "iter=10"
)
make test%testnum%
cls
echo Benchmarking %testfile% (%iter% iterations)...
echo ---------------------------
rem Run original %iter% times and get average
for /f "tokens=*" %%a in ('powershell -command "$times=@(); 1..%iter%|foreach{$times+=(measure-command {.\\examples\\%testfile%.bat}).TotalMilliseconds}; $avg=$times|measure-object -average|select-object -expand average; [math]::round($avg,3).tostring('0.000', [globalization.cultureinfo]::invariantculture)"') do (
set "original_avg=%%a"
)
rem Run compiled %iter% times and get average
for /f "tokens=*" %%a in ('powershell -command "$times=@(); 1..%iter%|foreach{$times+=(measure-command {.\\test.exe}).TotalMilliseconds}; $avg=$times|measure-object -average|select-object -expand average; [math]::round($avg,3).tostring('0.000', [globalization.cultureinfo]::invariantculture)"') do (
set "compiled_avg=%%a"
)
rem Remove .* from average values
for /f "tokens=1 delims=." %%a in ("%original_avg%") do (
set "original_avg=%%a"
)
for /f "tokens=1 delims=." %%a in ("%compiled_avg%") do (
set "compiled_avg=%%a"
)
rem Calculate speed ratio
for /f "tokens=*" %%a in ('powershell -command "[math]::round([double]%original_avg%/[double]%compiled_avg%, 1).tostring([globalization.cultureinfo]::invariantculture)"') do (
set "speed_ratio=%%a"
)
echo Original Average: %original_avg% ms
echo Compiled Average: %compiled_avg% ms
echo.
echo The compiled version is %speed_ratio% times the speed of the original script
echo ---------------------------