-
-
Save flameSla/b614b1c3ebccee156953c9d1689256ba to your computer and use it in GitHub Desktop.
benchmark.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param ( | |
[parameter(Mandatory=$true, Position=0)] | |
[array] | |
$saves, | |
[parameter(Mandatory=$true, Position=1)] | |
$ticks, | |
[parameter(Mandatory=$true, Position=2)] | |
$runs, | |
[parameter(Mandatory=$false, Position=3)] | |
[bool] | |
$ver = $false, | |
[parameter(Mandatory=$false, Position=4)] | |
[int] | |
$affinity = 0, | |
[parameter(Mandatory=$false, Position=5)] | |
[bool] | |
$del_outfile = $true, | |
[parameter(Mandatory=$false, Position=6)] | |
[bool] | |
$pause = $true | |
) | |
function get-verbose { | |
param ( | |
[parameter(Mandatory=$true, Position=0)] | |
[string]$input_file, | |
[parameter(Mandatory=$true, Position=1)] | |
[string]$output_file, | |
[parameter(Mandatory=$true, Position=2)] | |
[int]$ticks, | |
[parameter(Mandatory=$true, Position=3)] | |
[bool]$del_file | |
) | |
if( Test-Path -Path $output_file -PathType leaf ) | |
{ | |
if( $del_file ) | |
{ | |
rm $output_file | |
} | |
} | |
Copy-Item -Path $input_file -Destination ($output_file + "_full") | |
$data = Get-Content $input_file | |
[int]$current_line = 0 | |
[string]$values | |
[int] $run | |
$table=@{} | |
while ($current_line -lt $data.Length) | |
{ | |
if($data[$current_line].Contains("run ") ) | |
{ | |
$run = $data[$current_line].Substring(0,$data[$current_line].Length-1).Split(" ")[1] | |
$current_line += 1 | |
$values = $data[$current_line].Substring(0,$data[$current_line].Length-1).Split(",") | |
$current_line += 1 | |
if( $run -eq 1 ) | |
{ | |
$values -join ';' >> $output_file | |
foreach( $n in $values ){ $table[ $n ] = 0 } | |
} | |
[int]$tick = 0 | |
while($tick -lt $ticks) | |
{ | |
$val = $data[$current_line].Substring(0,$data[$current_line].Length-1).Split(",") | |
for ( $i=1; $i -lt $val.Count; $i += 1) | |
{ | |
$table[ $values[$i] ] += $val[$i] | |
} | |
$current_line += 1 | |
$tick +=1 | |
} | |
}#if($data[$current_line].Contains("run ") ) | |
else | |
{ | |
$current_line += 1 | |
} | |
}#while ($current_line -lt $data.Length) | |
$temp = foreach( $n in $values ){ "{0,6:F6}" -f ($table[$n]/1000000/$ticks/$run) } | |
$temp[0] = $ticks | |
$temp -join ";" >> $output_file | |
return | |
} | |
Write-Output "$(Get-Date)" | |
[string]$platform = "Windows" | |
echo "--benchmark-verbose = $ver" | |
echo "Runs = $runs" | |
echo "Maps:" | |
$saves | |
echo "`nTicks: $ticks" | |
echo "----------------------" >> test_results.txt | |
foreach ($save in $saves) | |
{ | |
#runs are indexed such that they are interleaved when testing, so no map has any substantial advantage to going first or last | |
$i = 0 | |
$avg_ms=0 | |
$min_ms=0 | |
$max_ms=0 | |
if($ver) | |
{ | |
#$argList = "--benchmark `"$save`" --benchmark-ticks $ticks --benchmark-runs $runs --benchmark-verbose `"wholeUpdate,gameUpdate,circuitNetworkUpdate,transportLinesUpdate,entityUpdate,electricNetworkUpdate,logisticManagerUpdate,constructionManagerUpdate,pathFinder,trains,trainPathFinder`" --disable-audio" | |
$argList = "--benchmark `"$save`" --benchmark-ticks $ticks --benchmark-runs $runs --benchmark-verbose `"all`" --disable-audio" | |
$platform = "WindowsVerbose" | |
$runs = 1 | |
} | |
else | |
{ | |
$argList = "--benchmark `"$save`" --benchmark-ticks $ticks --disable-audio" | |
} | |
#$argList = "--mod-directory null " + $argList | |
echo "`nCurrent map = `"$save`"" | |
$Min_avg = 99999999999999999.0 | |
while ($i -lt $runs) | |
{ | |
$process = Start-Process -PassThru -FilePath "factorio.exe" -ArgumentList $argList -RedirectStandardOutput temp1 | |
$process.PriorityClass = 128 | |
if($affinity -gt 0) | |
{ | |
$process.ProcessorAffinity = $affinity | |
} | |
$affinity = $process.ProcessorAffinity | |
$process.WaitForExit() | |
#perform a cleanup pass on the data, since depending on the time to benchmark a number of spaces will be added to the lines | |
(cat temp1) -replace '\s+', ' ' > temp | |
if($ver) | |
{ | |
$name = "$save.log" -replace '\\','-' | |
$name = "verbose\\" + $name | |
get-verbose -input_file temp1 -output_file $name -ticks $ticks -del_file $del_outfile | |
} | |
#rm temp1 | |
$map_name = $save | |
$avg_current = ((cat temp | Select-String "avg:") -split " ")[2] | |
$avg_ms += ((cat temp | Select-String "avg:") -split " ")[2] | |
$min_ms += ((cat temp | Select-String "avg:") -split " ")[5] | |
$max_ms += ((cat temp | Select-String "avg:") -split " ")[8] | |
$factorio_version = ((cat temp -First 1) -split " ")[5] | |
$execution_time = ((cat temp | Select-String "Performed") -split " ")[5] | |
$startup_time = ((cat temp | Select-String "Loading script.dat") -split " ")[1] | |
$end_time = ((cat temp -last 1) -split " ")[1] | |
$run_index = $i + 1 | |
# находим минимальное среднее | |
if($Min_avg -gt $avg_current) | |
{ | |
$Min_avg = $avg_current | |
} | |
Write-Host "run - " ($i+1)`t$execution_time ms`tProcessorAffinity=$affinity -foreground Green | |
#echo "$map_name,$run_index,$startup_time,$end_time,$avg_ms,$min_ms,$max_ms,$ticks,$execution_time,$effective_UPS,$factorio_version,$platform" >> test_results.txt | |
#echo "$map_name`t`t$avg_ms`t$min_ms`t$max_ms`t$factorio_version`t$platform" >> test_results.txt | |
$i++; | |
#if ( $i -eq $runs ){ Read-Host -Prompt "Press Enter to next" } | |
rm temp | |
} | |
$avg_ms /= $runs | |
$min_ms /= $runs | |
$max_ms /= $runs | |
Write-Host "`tavg - " ( [math]::Round( $avg_ms, 3 ) ) ms`tFPS = ( [math]::Round((1000 / $avg_ms), 2) ) -foreground Green | |
Write-Host "`tmin - " ( [math]::Round( $Min_avg, 3 ) ) ms`tFPS = ( [math]::Round((1000 / $Min_avg), 2) ) -foreground Green | |
'{0,-64} {1,-8} avg: {2,6:F3} ms min: {3,6:F3} ms max: {4,6:F3} ms {5,8} {6}' -f $map_name, $ticks, $avg_ms, $min_ms, $max_ms, $factorio_version, $platform >> test_results.txt | |
} | |
if($pause) | |
{ | |
Read-Host -Prompt "Press Enter to exit" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment