function Coalesce($a, $b) { if ($a -ne $null) { $a } else { $b } } function run() { $FACTORIO_BIN = Coalesce $FACTORIO_BIN ".\bin\x64\factorio.exe" if (-Not (Test-Path -PathType Leaf -LiteralPath "$FACTORIO_BIN")) { $FACTORIO_BIN = "${env:ProgramFiles(x86)}\Steam\steamapps\common\Factorio\bin\x64\factorio.exe" } $FB_HOST = Coalesce $FB_HOST "https://factoriobox.1au.us" $BENCH_TICKS = Coalesce $BENCH_TICKS 1000 $BENCH_RUNS = Coalesce $BENCH_RUNS 5 $FACTORIO_VERSION = &$FACTORIO_BIN --version | Select -First 1 $FACTORIO_VERSION_SHORT = ($FACTORIO_VERSION -split "\s+")[1] $TMP = $null if (!$MAP) { $URL = Coalesce $URL "$FB_HOST/map-version/$FACTORIO_VERSION_SHORT" $TMP = New-TemporaryFile echo "Downloading map..." Invoke-WebRequest -Uri $URL -OutFile $TMP $MAP = $TMP } $MAP_HASH = Get-FileHash $MAP -Algorithm sha256 | Select-Object -ExpandProperty Hash $TMP_MODS = New-TemporaryFile echo "Running benchmark..." &$FACTORIO_BIN --mod-directory "$TMP_MODS" --benchmark "$MAP" --benchmark-ticks $BENCH_TICKS --benchmark-runs $BENCH_RUNS --benchmark-verbose all 2>&1 | Out-String -Stream | Tee-Object -Variable FACTORIO_LOG | Select-String -Pattern 'Performed \d+ updates in \d+\.\d+ ms' | foreach {$_.Matches.Value} Remove-Item $TMP_MODS $TIMES = (($FACTORIO_LOG | Select-String Performed | foreach{ ($_.Line.Trim() -split "\s+")[4]} )) if (!$TIMES) { echo "Benchmark failed" echo $FACTORIO_LOG Return } $UPS = [math]::Round(1000 * $BENCH_TICKS / ($TIMES | Measure-Object -Minimum | Select -Expand Minimum)) echo "Map benchmarked at $UPS UPS" if ($TMP) { Remove-Item $MAP } $RESULT_ID = (Invoke-WebRequest -UseBasicParsing $FB_HOST/result -Method POST -Body "v2 windows $MAP_HASH $FACTORIO_VERSION $BENCH_TICKS $BENCH_RUNS $(Get-WmiObject win32_processor | Select addresswidth,currentclockspeed,currentvoltage,datawidth,extclock,l2cachesize,l2cachespeed,l3cachesize,l3cachespeed,maxclockspeed,name,numberofcores,numberofenabledcore,numberoflogicalprocessors,threadcount | ConvertTo-Json -Compress) $(Get-WmiObject win32_physicalmemory | Select capacity,configuredclockspeed,configuredvoltage,datawidth,devicelocator,manufacturer,maxvoltage,model,partnumber,speed | ConvertTo-Json -Compress) $($FACTORIO_LOG | Select-String -Pattern 'Performed \d+ updates in \d+\.\d+ ms' | foreach {$_.Matches.Value} | Out-String -Width 100000) $($FACTORIO_LOG | Select-String '^[^ ]' | Out-String -Width 100000)").Content echo "Share your benchmark at: $FB_HOST/result/$RESULT_ID" } run Pause