BenchmarkTools macros with Books

jvaverka
Mon, 31 Jan 2022 20:51:38 +0000
Tooling

Given this example weaved output from a Julia Markdown Document:

Generated with this code block:

A = rand(100,100)
B = rand(100,100)
C = rand(100,100)
using BenchmarkTools
function inner_rows!(C,A,B)
  for i in 1:100, j in 1:100
    C[i,j] = A[i,j] + B[i,j]
  end
end
@btime inner_rows!(C,A,B)

How might I achieve the same effect using Books.jl?

So far in my module I have defined a function, inner_rows!:

function inner_rows!(C,A,B)
    for i in 1:100, j in 1:100
        C[i,j] = A[i,j] + B[i,j]
    end
end

Which is called on the page with 3 jl code blocks:

sc("using BenchmarkTools")

s = """
    A = rand(100,100)
    B = rand(100,100)
    C = rand(100,100)
    """
sc(s)

scob("@btime BookTest.inner_rows!(C,A,B) |> string")

Running gen() is successful, but upon serve() the macro output is not shown. Instead only the return value, nothing, is shown.

Is there a way to do this in Books.jl?

6 posts - 2 participants