Skip to content

Commit 72a2bca

Browse files
committed
[[ Benchmarks ]] Add support for variants of a single benchmark.
A single benchmark command may now issue multiple StartTiming and StopTiming calls, passing an optional parameter 'variant'. The log output has been changed to be lines of the form: <BenchmarkName> tab <Variant> tab <TimeInMS> If no 'variant' parameter is given to StartTiming, it is presumed to be empty. Additional a 'BenchmarkLoadNativeTextFile' command has been added which loads the given file, searched for relative to the benchmark script file, as a native encoded text file.
1 parent aa72ab1 commit 72a2bca

File tree

2 files changed

+43
-12
lines changed

2 files changed

+43
-12
lines changed

benchmarks/_benchmarklib.livecodescript

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,31 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
2525
----------------------------------------------------------------
2626

2727
local sBenchmarkStartTime
28+
local sBenchmarkVariant
2829

29-
on BenchmarkStartTiming
30-
put the millisecs into sBenchmarkStartTime
30+
on BenchmarkStartTiming pVariant
31+
put pVariant into sBenchmarkVariant
32+
put the millisecs into sBenchmarkStartTime
3133
end BenchmarkStartTiming
3234

3335
on BenchmarkStopTiming
34-
write (the millisecs - sBenchmarkStartTime) to stdout
36+
write sBenchmarkVariant & tab & (the millisecs - sBenchmarkStartTime) & return to stdout
3537
end BenchmarkStopTiming
3638

39+
on BenchmarkLoadNativeTextFile pFilename
40+
set the itemDelimiter to slash
41+
put item 1 to -2 of the filename of the target & slash & pFilename into pFilename
42+
43+
get url ("binfile:" & pFilename)
44+
if the result is not empty then
45+
throw "BenchmarkLoadNativeTextFile" && quote & pFilename & quote && "failed" & return & it
46+
end if
47+
replace crlf with lf in it
48+
replace numToChar(13) with lf in it
49+
50+
return it
51+
end BenchmarkLoadNativeTextFile
52+
3753
on errorDialog executionError, parseError
3854
write executionError & return to stderr
3955
quit 1

benchmarks/_benchmarkrunner.livecodescript

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,11 @@ end runSingleScript
214214
-- Run a specific named benchmark command tCommand in a script file
215215
-- tScriptFile
216216
private command runSingleCommand pInfo, pScriptFile, pCommand
217-
local tArg, tCommandLine
218-
219-
write "Running " & pCommand & "... " to stdout
217+
local tBenchmarkName
218+
put char 10 to -1 of pCommand into tBenchmarkName
219+
write "Running " & tBenchmarkName & "..." & return to stdout
220220

221+
local tArg, tCommandLine
221222
repeat for each element tArg in pInfo["self-command"]
222223
put tArg & " " after tCommandLine
223224
end repeat
@@ -226,18 +227,32 @@ private command runSingleCommand pInfo, pScriptFile, pCommand
226227

227228
-- Invoke the test in a subprocess. This ensures that we can detect
228229
-- if a crash occurs
229-
local tBenchmarkTime, tBenchmarkExitStatus
230-
put shell(tCommandLine) into tBenchmarkTime
230+
local tBenchmarkTimes, tBenchmarkExitStatus
231+
put shell(tCommandLine) into tBenchmarkTimes
231232
put the result into tBenchmarkExitStatus
232233

233-
-- Check the exit status.
234+
-- The output from the shell will be a list of tab separated lines.
235+
-- <variantname> tab <timetaken>
236+
237+
-- Check the exit status and process for logging.
234238
if tBenchmarkExitStatus is not empty then
235-
put "failed" into tBenchmarkTime
239+
write tab & "failed" & return to stdout
240+
write tBenchmarkTimes & return to stderr
241+
return tBenchmarkName & tab & "failed" & return
236242
end if
237243

238-
write tBenchmarkTime & " ms" & return to stdout
244+
local tLog
245+
set the itemDelimiter to tab
246+
repeat for each line tResult in tBenchmarkTimes
247+
if item 1 of tResult is not empty then
248+
write tab & item 1 of tResult & space & item 2 of tResult & " ms" & return to stdout
249+
else
250+
write tab & item 2 of tResult & " ms" & return to stdout
251+
end if
252+
put tBenchmarkName & tab & tResult & return after tLog
253+
end repeat
239254

240-
return pCommand & tab & tBenchmarkTime & return
255+
return tLog
241256
end runSingleCommand
242257

243258
-- Get all livecode script files beneath the CWD, apart from

0 commit comments

Comments
 (0)