Skip to content

Commit 0ddf145

Browse files
committed
modified: benchmark/runbench.jl
1 parent 8bf572a commit 0ddf145

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

benchmark/runbench.jl

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,12 @@ ON CONFLICT (key) DO UPDATE SET value = excluded.value
282282
end
283283

284284
function validate_schema_version!(db::SQLite.DB, path::AbstractString)
285-
schema_rows = collect(DBInterface.execute(db, "SELECT value FROM benchledger_metadata WHERE key = 'schema_version'"))
286-
if isempty(schema_rows)
285+
# Avoid collect(...) here: SQLite.jl can materialize this single-column result as missing.
286+
schema_iter = iterate(DBInterface.execute(db, "SELECT value FROM benchledger_metadata WHERE key = 'schema_version'"))
287+
if schema_iter === nothing
287288
error("Unsupported BenchLedger database in $(path): missing benchledger_metadata.schema_version.")
288289
end
289-
schema_version = String(first(schema_rows).value)
290+
schema_version = String(schema_iter[1].value)
290291
schema_version == Benchledger_Schema_Version || error("Unsupported BenchLedger schema version in $(path): $(schema_version). Expected $(Benchledger_Schema_Version).")
291292

292293
result_columns = Set{String}()
@@ -341,23 +342,32 @@ function metric_rows(benchmark_path::Vector{String}, value)
341342
error("Unsupported benchmark leaf at $(join(benchmark_path, " / ")): $(typeof(value)). Provide a BenchmarkTools.Trial or normalize custom results into BenchmarkMetricRow rows.")
342343
end
343344

344-
metric_rows(results::BenchmarkGroup) = append_metric_rows!(BenchmarkMetricRow[], results, String[])
345345
metric_rows(rows::Vector{BenchmarkMetricRow}) = rows
346346
metric_rows(rows::AbstractVector{<:BenchmarkMetricRow}) = BenchmarkMetricRow[row for row in rows]
347347
metric_rows(rows::AbstractVector{<:NamedTuple}) = [metric_row(row) for row in rows]
348+
metric_rows(results::Tuple{<:AbstractVector{<:NamedTuple}, <:BenchmarkGroup}) = vcat(metric_rows(results[1]), metric_rows(results[2]))
348349

349-
function append_metric_rows!(rows::Vector{BenchmarkMetricRow}, results::BenchmarkGroup, prefix::Vector{String})
350+
function flatten_trial_rows(results::BenchmarkGroup, prefix::Vector{String}=String[])
351+
rows = Tuple{Vector{String}, Any}[]
350352
for (name, value) in pairs(results)
351353
benchmark_path = [prefix; String(name)]
352354
if value isa BenchmarkGroup
353-
append_metric_rows!(rows, value, benchmark_path)
355+
append!(rows, flatten_trial_rows(value, benchmark_path))
354356
else
355-
append!(rows, metric_rows(benchmark_path, value))
357+
push!(rows, (benchmark_path, value))
356358
end
357359
end
358360
rows
359361
end
360362

363+
function metric_rows(results::BenchmarkGroup)
364+
rows = BenchmarkMetricRow[]
365+
for (benchmark_path, value) in flatten_trial_rows(results)
366+
append!(rows, metric_rows(benchmark_path, value))
367+
end
368+
rows
369+
end
370+
361371
function benchmark_id(path::Vector{String})
362372
encoded = IOBuffer()
363373
for segment in path

0 commit comments

Comments
 (0)