Skip to content

Commit

Permalink
Rename NoTimerOutput -> NullTimer
Browse files Browse the repository at this point in the history
  • Loading branch information
jipolanco committed Mar 23, 2021
1 parent 5a8dfa4 commit baf68f9
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 35 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,9 @@ By default, debug timings are disabled, and this conditional should be optimized
If a user calls `TimerOutputs.enable_debug_timings(<module>)`, the `<module>.timeit_debug_enabled()` method will be redefined, causing all dependent methods to be recompiled within that module.
This may take a while, and hence is intended only for debugging usage, however all calls to `@timeit_debug` (within that Module) will thereafter be enabled.

As an alternative to `@timeit_debug`, this package also provides a `NoTimerOutput` type that allows disabling all timings with zero overhead.
As an alternative to `@timeit_debug`, this package also provides a `NullTimer` type that allows disabling all timings with zero overhead.
This type represents a dummy timer which acts as a drop-in replacement for regular `TimerOutput`s.
From a user's perspective, it suffices to replace `to = TimerOutput()` by `to = NoTimerOutput()` at the beginning of their code to fully disable timers.
From a user's perspective, it suffices to replace `to = TimerOutput()` by `to = NullTimer()` at the beginning of their code to fully disable timers.

## Author

Expand Down
30 changes: 0 additions & 30 deletions src/NoTimerOutput.jl

This file was deleted.

30 changes: 30 additions & 0 deletions src/NullTimer.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
struct NullTimer <: AbstractTimerOutput
name::String
NullTimer(label::String = "root") = new(label)
end

isdummy(::NullTimer) = true

Base.copy(to::NullTimer) = NullTimer(to.name)

# Add definitions for exported methods
reset_timer!(to::NullTimer) = to
timeit(f::Function, ::NullTimer, ::String) = f()
enable_timer!(::NullTimer) = true
disable_timer!(::NullTimer) = false
flatten(to::NullTimer) = to

ncalls(::NullTimer) = 0
time(::NullTimer) = 0
allocated(::NullTimer) = 0
tottime(::NullTimer) = 0
totallocated(::NullTimer) = 0

complement!(to::NullTimer) = to

Base.haskey(::NullTimer, ::String) = false
Base.getindex(::NullTimer, key::String) = throw(KeyError(key))

function Base.show(io::IO, to::NullTimer)
print(io, "Timer \"", to.name, "\" is a dummy timer")
end
4 changes: 2 additions & 2 deletions src/TimerOutputs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module TimerOutputs
import Base: show, time_ns
export TimerOutput, @timeit, @timeit_debug, reset_timer!, print_timer, timeit,
enable_timer!, disable_timer!, @notimeit
export AbtractTimerOutput, NoTimerOutput
export AbtractTimerOutput, NullTimer

# https://github.com/JuliaLang/julia/pull/33717
if VERSION < v"1.4.0-DEV.475"
Expand All @@ -20,7 +20,7 @@ using Printf


include("TimerOutput.jl")
include("NoTimerOutput.jl")
include("NullTimer.jl")
include("show.jl")
include("utilities.jl")

Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ end

@testset "dummy timers" begin
to = TimerOutput()
nt = NoTimerOutput()
nt = NullTimer()

@test repr(nt) == "Timer \"root\" is a dummy timer"

Expand Down

0 comments on commit baf68f9

Please sign in to comment.