BenchmarkTools.jl icon indicating copy to clipboard operation
BenchmarkTools.jl copied to clipboard

No output when running @benchmark from script file

Open chw90 opened this issue 3 years ago • 3 comments

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.

chw90 avatar Apr 20 '22 09:04 chw90

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.

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.

danielsoutar avatar May 18 '22 16:05 danielsoutar

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.

Sean1708 avatar Jun 07 '22 10:06 Sean1708