Skip to content

Throw more meaningful error when calling @bcomp with only one function #8

@ajinkya-k

Description

@ajinkya-k

Currently calling @bcomp with only one function say f as follows @bcomp rand(10) f(_) gives a cryptic error because the length function is being invoked on a Chairmarks.Benchmark object, which is obviously going to fail. The real reason this fails is because @bcomp is meant to be used only when comparing two or more functions.

I think we should catch this behavior and throw an error that says something like @bcomp is for comarping two or more functions. Please use @bs for single function benchmarking. I don't know enough about macros to be able to do that though. Maybe @LilithHafner can help

Here's an example of the error:

julia> @bcomp 500 rand(_)
ERROR: MethodError: no method matching length(::Chairmarks.Benchmark)
The function `length` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  length(::Profile.HeapSnapshot.Nodes)
   @ Profile ~/.julia/juliaup/julia-1.11.2+0.aarch64.apple.darwin14/share/julia/stdlib/v1.11/Profile/src/heapsnapshot_reassemble.jl:52
  length(::Core.SimpleVector)
   @ Base essentials.jl:933
  length(::LibGit2.GitBlob)
   @ LibGit2 ~/.julia/juliaup/julia-1.11.2+0.aarch64.apple.darwin14/share/julia/stdlib/v1.11/LibGit2/src/blob.jl:3
  ...

Stacktrace:
 [1] length(g::Base.Generator{Chairmarks.Benchmark, var"#115#117"})
   @ Base ./generator.jl:51
 [2] _similar_shape(itr::Base.Generator{Chairmarks.Benchmark, var"#115#117"}, ::Base.HasLength)
   @ Base ./array.jl:663
 [3] collect(itr::Base.Generator{Chairmarks.Benchmark, var"#115#117"})
   @ Base ./array.jl:790
 [4] macro expansion
   @ ~/projects/julia_repos/PrettyChairmarks.jl/src/PrettyChairmarks.jl:96 [inlined]
 [5] top-level scope
   @ REPL[22]:1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions