BenchmarkTools.jl
BenchmarkTools.jl copied to clipboard
No output when running @benchmark from script file
Is there a way to define benchmarks using @benchmark in a script file script.jl and run them via $ julia script.jl?
From the runtime of the Julia command, seems that the benchmarks are actually run, but theres nothing printed to my shell.
Is there a way to define benchmarks using
@benchmarkin a script filescript.jland run them via$ julia script.jl?From the runtime of the Julia command, seems that the benchmarks are actually run, but theres nothing printed to my shell.
I second this. It'd be fantastic if there was a way of being able to get the wonderful visualisations of the REPL in an automated fashion with a script. I'm interested in tracking performance in my codebase and one-off benchmarks, while still useful, are far more limited than if I were to have scripts that could automate the process for me.
As far as I can tell @benchmark isn't responsible for doing any printing whatsoever, and it shouldn't be responsible for that either IMO. You get a pretty output in the REPL because the REPL implicitly calls show on result of the the last expression. To get that output from a script you can either use
display(@benchmark function_to_be_benchmarked())
if you just want the output to go to whatever the default display is, or
show(stdout, "text/plain", @benchmark function_to_be_benchmarked())
if you specifically want it to go to stdout.