1
- # Factorio Benchmark Script v1.0.0
1
+ # Factorio Benchmark Script v1.1.0
2
+ # Depends on Import-Excel https://github.com/dfinke/ImportExcel for -verboseOutput
2
3
param (
3
4
4
5
# #################
@@ -43,8 +44,11 @@ param (
43
44
# ADVANCED SETTINGS #
44
45
# ####################
45
46
46
- # Output filename
47
- [string ]$outputName = " results.csv" ,
47
+ # Output csv filename
48
+ [string ]$outputName = " results" ,
49
+
50
+ # Output xlsx verbose filename
51
+ [string ]$outputNameVerbose = " verbose" ,
48
52
49
53
# Which folder to output results into.
50
54
[string ]$outputFolder = " .\Results\" ,
@@ -61,6 +65,18 @@ param (
61
65
# If given disables automatic mod disabling feature
62
66
[switch ]$enableMods = $false ,
63
67
68
+ # If given enables verbose mode which logs per-tick benchmarks
69
+ [switch ]$verboseResult = $false ,
70
+
71
+ # Which items are selected for verbose logging
72
+ #
73
+ # Available options are:
74
+ #
75
+ # tick,timestamp,wholeUpdate,latencyUpdate,gameUpdate,circuitNetworkUpdate,transportLinesUpdate,fluidsUpdate,heatManagerUpdate,entityUpdate,particleUpdate,mapGenerator,mapGeneratorBasicTilesSupportCompute,mapGeneratorBasicTilesSupportApply,mapGeneratorCorrectedTilesPrepare,mapGeneratorCorrectedTilesCompute,mapGeneratorCorrectedTilesApply,mapGeneratorVariations,mapGeneratorEntitiesPrepare,mapGeneratorEntitiesCompute,mapGeneratorEntitiesApply,crcComputation,electricNetworkUpdate,logisticManagerUpdate,constructionManagerUpdate,pathFinder,trains,trainPathFinder,commander,chartRefresh,luaGarbageIncremental,chartUpdate,scriptUpdate,
76
+ #
77
+ # tick must be one of the selected items, otherwise the script won't work
78
+ [string ]$verboseItems = " tick,wholeUpdate,wholeUpdate,gameUpdate,circuitNetworkUpdate,transportLinesUpdate,fluidsUpdate,entityUpdate,electricNetworkUpdate,logisticManagerUpdate,trains,trainPathFinder" ,
79
+
64
80
# Can customize used CPU priority.
65
81
[string ]$cpuPriority = " High" ,
66
82
@@ -71,17 +87,25 @@ param (
71
87
# Eg. enabling core 1, 3 and 5 is 1 + 4 + 16 = 21
72
88
# 0 to disable feature
73
89
[int ]$cpuAffinity = 0
74
-
75
- # If given, don't interleave runs and use factorio.exe run mechanism which is faster in real time
76
- # TODO: implement
77
- # [switch]$noRunInterleaving = $false,
78
90
)
79
91
# End of user variables
80
92
81
93
$ErrorActionPreference = " Stop"
82
94
95
+ $excelEnabled = $false
96
+ if (Get-Command Export-Excel - errorAction SilentlyContinue)
97
+ {
98
+ $excelEnabled = $true
99
+ }
100
+ elseif ($verboseResult ) {
101
+ Write-Output " `n UNMET DEPENDENCY. Export-Excel cmdlet not found for verbose mode." `
102
+ " Please install it by running this command in powershell:" `
103
+ " `n Install-Module ImportExcel -scope CurrentUser`n " `
104
+ " Script will run normally but verbose excel file won't be generated."
105
+ }
106
+
83
107
# Collect the saves to benchmark
84
- echo " "
108
+ Write-Output " "
85
109
if ($pattern -ne " " ) {
86
110
[array ]$saves = dir $savepath - file - recurse | where {$_.BaseName -Match $pattern }
87
111
$saveFoundMessage = " found matching pattern '$pattern '"
@@ -92,17 +116,17 @@ else {
92
116
}
93
117
94
118
if ($saves.length -ne 0 ) {
95
- echo " Following saves ${saveFoundMessage} :"
119
+ Write-Output " Following saves ${saveFoundMessage} :"
96
120
}
97
121
else {
98
- echo " No saves $saveFoundMessage ."
99
- echo " "
122
+ Write-Output " No saves $saveFoundMessage ."
123
+ Write-Output " "
100
124
exit
101
125
}
102
126
103
- echo " "
104
- echo $ ($saves | select - ExpandProperty BaseName)
105
- echo " "
127
+ Write-Output " "
128
+ Write-Output $ ($saves | select - ExpandProperty BaseName)
129
+ Write-Output " "
106
130
Write-Host - NoNewline " Executing benchmark after confirmation. Ctrl-c to cancel. "
107
131
pause
108
132
@@ -113,11 +137,17 @@ try {
113
137
# Remove illegal filename characters from pattern for output filename
114
138
$sanitized_pattern = ($pattern.Split ([IO.Path ]::GetInvalidFileNameChars()) -join ' _' ) + " "
115
139
}
116
- [System.IO.FileInfo ]$output = Join-Path $outputFolder - ChildPath ($sanitized_pattern + $outputName )
140
+ [System.IO.FileInfo ]$output = Join-Path $outputFolder - ChildPath ($sanitized_pattern + $outputName + " .csv" )
141
+ [System.IO.FileInfo ]$outputVerbose = Join-Path $outputFolder - ChildPath ($sanitized_pattern + $outputNameVerbose + " .xlsx" )
117
142
118
143
# Delete output file if feature is enabled
119
- if (($clearOutputFile ) -and (Test-Path $output )) {
120
- rm $output
144
+ if ($clearOutputFile ) {
145
+ if (Test-Path $output ) {
146
+ rm $output
147
+ }
148
+ if (Test-Path $outputVerbose ) {
149
+ rm $outputVerbose
150
+ }
121
151
}
122
152
123
153
# Check if output file already exists
@@ -126,41 +156,47 @@ try {
126
156
[Void ](New-Item - Force (Split-Path - Path $output ) - ItemType Directory)
127
157
128
158
# Create output and print headers
129
- echo " save_name,run,startup_time_s,end_time_s,avg_ms,min_ms,max_ms,ticks,execution_time_ms,effective_UPS,version,platform,calibration " > $output
159
+ Write-Output " Save,Run,Startup time,End time,Avg ms,Min ms,Max ms,Ticks,Execution Time ms,Effective UPS,Version,Platform,Calibration " > $output
130
160
}
131
161
132
162
# Mod disabling block
133
163
if (-not $enableMods ) {
134
- $mods_path = Join-Path - Path $configpath - ChildPath " mods"
135
- $backup_path = Join-Path - Path $configpath - ChildPath " mods_disabled"
136
- if (Test-Path $mods_path ) {
137
- if (-not (Test-Path $backup_path )) {
138
- echo " Disabling mods."
139
- Move-Item - Path $mods_path - Destination $backup_path
164
+ $modsPath = Join-Path - Path $configpath - ChildPath " mods"
165
+ $backupPath = Join-Path - Path $configpath - ChildPath " mods_disabled"
166
+ if (Test-Path $modsPath ) {
167
+ if (-not (Test-Path $backupPath )) {
168
+ Write-Output " Disabling mods."
169
+ Move-Item - Path $modsPath - Destination $backupPath
140
170
}
141
171
else {
142
- echo " Mods already disabled previously. Doing nothing."
172
+ Write-Output " Mods already disabled previously. Doing nothing."
143
173
}
144
174
}
145
175
else {
146
- echo " Mod folder not found. Doing nothing."
176
+ Write-Output " Mod folder not found. Doing nothing."
147
177
}
148
178
}
149
179
150
- echo " "
180
+ Write-Output " "
151
181
# Main benchmark loop
152
182
for ($i = 0 ; $i -lt $runs ; $i ++ ) {
153
183
for ($j = 0 ; $j -lt $saves.length ; $j ++ ) {
154
184
$run = $i + 1
155
185
$save = $saves [$j ].FullName
156
- $save_name = $saves [$j ].BaseName
157
- $log_path = Join-Path $outputFolder ($save_name + " Run" + $run + " .log" )
186
+ $saveName = $saves [$j ].BaseName
187
+ $runName = $saveName + " Run " + $run
188
+ $logPath = Join-Path $outputFolder ($runName + " .log" )
158
189
159
- Write-Host - NoNewline " Benchmarking ' $save_name ' Run $run `t "
190
+ Write-Host - NoNewline " Benchmarking $runName `t "
160
191
161
192
# Run factorio
162
- $arg_list = " --benchmark `" $save `" --benchmark-ticks $ticks --disable-audio"
163
- $process = Start-Process - PassThru - FilePath $executable - ArgumentList $arg_list - RedirectStandardOutput $log_path
193
+ $argList = " --benchmark `" $save `" --benchmark-ticks $ticks --disable-audio"
194
+
195
+ if ($verboseResult ) {
196
+ $argList += " --benchmark-verbose " + $verboseItems
197
+ }
198
+
199
+ $process = Start-Process - PassThru - FilePath $executable - ArgumentList $argList - RedirectStandardOutput $logPath
164
200
165
201
# Set process flags and wait for execution to finish
166
202
$process.PriorityClass = $cpuPriority
@@ -169,43 +205,70 @@ try {
169
205
}
170
206
$process.WaitForExit ()
171
207
172
- # Perform a cleanup pass on the data, since depending on the time to benchmark a number of spaces will be added to the lines
173
- $log_data = (Get-Content $log_path ) -replace ' ^\s+' , ' '
174
- $log_data | Set-Content $log_path
208
+ # Perform a cleanup pass on the data, since depending on the time to benchmark a number of spaces will be added to
209
+ # the lines
210
+ $logData = (Get-Content $logPath ) -replace ' ^\s+' , ' '
211
+ $logData | Set-Content $logPath
175
212
176
213
# Parse data
177
- $avg_ms = (($log_data | Select-String " avg:" ) -split " " )[1 ]
178
- $min_ms = (($log_data | Select-String " avg:" ) -split " " )[4 ]
179
- $max_ms = (($log_data | Select-String " avg:" ) -split " " )[7 ]
180
- $version = (($log_data | Select-Object - First 1 ) -split " " )[4 ]
181
- $execution_time_ms = (($log_data | Select-String " Performed" ) -split " " )[4 ]
182
- $startup_time_s = (($log_data | Select-String " Loading script.dat" ) -split " " )[0 ]
183
- $end_time_s = (($log_data | Select-Object - Last 1 ) -split " " )[0 ]
184
- $effective_UPS = [math ]::Round((1000 * $ticks / $execution_time_ms ), 2 )
214
+ $avg = (($logData | Select-String " avg:" ) -split " " )[1 ]
215
+ $min = (($logData | Select-String " avg:" ) -split " " )[4 ]
216
+ $max = (($logData | Select-String " avg:" ) -split " " )[7 ]
217
+ $version = (($logData | Select-Object - First 1 ) -split " " )[4 ]
218
+ $executionTime = (($logData | Select-String " Performed" ) -split " " )[4 ]
219
+ $startupTime = (($logData | Select-String " Loading script.dat" ) -split " " )[0 ]
220
+ $endTime = (($logData | Select-Object - Last 1 ) -split " " )[0 ]
221
+ $effectiveUPS = [math ]::Round((1000 * $ticks / $executionTime ), 2 )
185
222
186
223
# Save the results
187
- echo " $save_name ,$run ,$startup_time_s ,$end_time_s ,$avg_ms ,$min_ms ,$max_ms ,$ticks ,$execution_time_ms ,$effective_UPS ,$version ,$platform ,$calibration " >> $output
188
-
189
- echo " end_time $end_time_s seconds"
224
+ Write-Output " $ ( $executionTime / 1000 ) seconds"
225
+ Write-Output " $saveName ,$run ,$startupTime ,$endTime ,$avg ,$min ,$max ,$ticks ,$executionTime ,$effectiveUPS ,$version ,$platform ,$calibration " >> $output
226
+
227
+ # If verbose result is enabled produce a separarte excel file with verbose results
228
+ if (($verboseResult ) -and ($excelEnabled )) {
229
+ $time = Get-Date - Format " HHmm "
230
+
231
+ # Select run-specific lines
232
+ # remove 't' from tick number
233
+ $verboseData = $logData `
234
+ | Select-String - Pattern " (^tick,)|(^t\d+)," `
235
+ | ForEach-Object {$_ -Replace " ^t(\d+)" , ' $1' } `
236
+ | ConvertFrom-Csv `
237
+
238
+ # Change to milliseconds and make ticks 1-based
239
+ $verboseData | ForEach-Object {
240
+ foreach ($property in $_.PSObject.Properties ) {
241
+ if ($property.Name -eq " tick" ) {
242
+ [int ]$property.Value += 1
243
+ }
244
+ else {
245
+ $property.Value = $property.Value / 1000000
246
+ }
247
+ }
248
+ }
249
+
250
+ # Output excel file
251
+ $verboseData | Export-Excel - AutoSize - WorksheetName ($time + $runName ) $outputVerbose
252
+ }
190
253
191
254
if (-not ($keepLogs )) {
192
- rm " $log_path "
255
+ rm " $logPath "
193
256
}
194
257
}
195
258
}
196
259
}
197
260
# Cleanup
198
261
finally {
199
262
if (-not $enableMods ) {
200
- if (Test-Path $backup_path ) {
201
- if (Test-Path $mods_path ) {
202
- echo " `n Restoring original mods."
203
- mv - Force (Join-Path - Path $backup_path - ChildPath " \*" ) $mods_path
204
- rm $backup_path
263
+ if (Test-Path $backupPath ) {
264
+ if (Test-Path $modsPath ) {
265
+ Write-Output " `n Restoring original mods."
266
+ mv - Force (Join-Path - Path $backupPath - ChildPath " \*" ) $modsPath
267
+ rm $backupPath
205
268
}
206
269
else {
207
- echo " Mods folder not created. Probably factorio didn't run. Restoring mods."
208
- mv $backup_path $mods_path
270
+ Write-Output " Mods folder not created. Probably factorio didn't run. Restoring mods."
271
+ mv $backupPath $modsPath
209
272
}
210
273
}
211
274
}
0 commit comments