Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom columns to output #138

Open
0x0f0f0f opened this issue Nov 6, 2021 · 0 comments
Open

Add custom columns to output #138

0x0f0f0f opened this issue Nov 6, 2021 · 0 comments

Comments

@0x0f0f0f
Copy link

0x0f0f0f commented Nov 6, 2021

Idea to add custom columns to the tables:

@timeit could take an additional NamedTuple that refers to custom, user specified columns.
addcolumn! can be used to insert a new column in a TimerOutput.
setaccumulator! could be used to specify which function is used to accumulate the custom value in a custom column. Default can be +.

to = TimerOutput()
addcolumn!(to, :foo, 0) # last arg is default value for new entries
setaccumulator!(to, :foo, (+)) # function f to compute accumulated = f(accumulated, new_value) 
addcolumn!(to, :bar, 1)
setaccumulator!(to, :bar, (*))

@timeit to "nest 1" begin
    sleep(0.1)
    @timeit to "level 2.1" sleep(0.1) (foo=1, bar=2)
    for i in 1:20; @timeit to "level 2.2" sleep(0.02) (,bar=2); end
end
@timeit to "nest 2" begin
    for i in 1:30; @timeit to "level 2.1" sleep(0.01); end
    @timeit to "level 2.2" sleep(0.1) (foo=4.5, bar=3)
end

Inside of begin ... end blocks, another macro @accum can be used in order to accumulate values computed inside a timed block.

function f(x) = (sleep(rand(1:x)); rand(1:x))

addcolumn!(to, :randn, 0)
@timeit to "rand num" begin 
    n = f(10)
    @accum to (,randn=n) # should not be timed
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant