Skip to content

Commit

Permalink
Add tests for enabling and disabling timings
Browse files Browse the repository at this point in the history
  • Loading branch information
efaulhaber committed Jun 7, 2024
1 parent 2ac2256 commit e4c912d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/TrixiBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ include("trixi_include.jl")
include("trixi_timeit.jl")

export trixi_include
export @trixi_timeit, timer, timeit_debug_enabled, disable_debug_timings
export @trixi_timeit, timer, timeit_debug_enabled,
disable_debug_timings, enable_debug_timings

function _precompile_manual_()
@assert Base.precompile(Tuple{typeof(trixi_include), String})
Expand Down
43 changes: 43 additions & 0 deletions test/test_timers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,47 @@
# Compare against empty timer output
@test actual == expected
end

@testset verbose=true "disable and enable timings" begin
# Start with empty timer output
TrixiBase.TimerOutputs.reset_timer!(timer())

# Disable timings
disable_debug_timings()

# These two timings should be disabled
@trixi_timeit timer() "test timer" sin(0.0)
@trixi_timeit timer() "test timer" sin(0.0)

# Disable timings
enable_debug_timings()

# This timing should be counted
@trixi_timeit timer() "test timer 2" sin(0.0)

println(timer())

timer_output = """
─────────────────────────────────────────────────────────────────────────
Time Allocations
─────────────────────── ────────────────────────
Tot / % measured: 23.7ms / 0.0% 1.00MiB / 0.0%
Section ncalls time %tot avg alloc %tot avg
─────────────────────────────────────────────────────────────────────────
test timer 2 1 875ns 100.0% 875ns 48.0B 100.0% 48.0B
─────────────────────────────────────────────────────────────────────────
"""
# Remove "Tot / % measured" line and trailing white spaces and replace
# the "test timer" line (but don't remove it, we want to check that it's there).
expected = replace(timer_output, r"Tot / % measured: .*" => "",
r"\s+\n" => "\n",
r"test timer 2 1 .*B\n" => "test timer 2 1")
actual = replace(repr(timer()) * "\n", r"Tot / % measured: .*" => "",
r"\s+\n" => "\n",
r"test timer 2 1 .*B\n" => "test timer 2 1")

# Compare against empty timer output
@test actual == expected
end
end;

0 comments on commit e4c912d

Please sign in to comment.