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 StopWatch? See suggested implementation. #100

Closed
dataPulverizer opened this issue Feb 9, 2018 · 3 comments
Closed

Add StopWatch? See suggested implementation. #100

dataPulverizer opened this issue Feb 9, 2018 · 3 comments
Labels

Comments

@dataPulverizer
Copy link

Add simple stopwatch, see below for basic suggested implementation:

mutable struct StopWatch
	t1::Float64
	t2::Float64
	StopWatch() = new(NaN, NaN)
end

function start!(sw::StopWatch)::Nothing
  sw.t1 = time()
  Nothing()
end

function stop!(sw::StopWatch)::Nothing
	sw.t2 = time()
	Nothing()
end

function reset!(sw::StopWatch)::Nothing
	sw.t2 = sw.t1 = NaN
  Nothing()
end

peek(sw::StopWatch) = isnan(sw.t1) ? throw("StopWatch ($sw) has not been started.") : isnan(sw.t2) ? time() - sw.t1 : sw.t2 - sw.t1
# duration(sw::StopWatch) = sw.t2 - sw.t1

# Demo
cl = StopWatch() # peek(cl) # error
start!(cl); sleep(2); peek(cl)
sleep(1); stop!(cl); peek(cl); reset!(cl)

Because sometimes you just want a stop watch.

@ararslan
Copy link
Member

ararslan commented Feb 9, 2018

If I understand correctly this is like tic and toq from Julia < 0.7, right?

@dataPulverizer
Copy link
Author

dataPulverizer commented Feb 9, 2018

To be honest, I didn't know about tic and toq but I get the general idea yes.

@gdalle
Copy link
Collaborator

gdalle commented Jun 13, 2023

Here is why these were deprecated: JuliaLang/julia#17046

Basically a stopwatch like this encourages people to benchmark in the global scope, which is a bad idea. I don't think it belongs in BenchmarkTools (but maybe it already exists elsewhere?)

@gdalle gdalle added the wontfix label Jun 13, 2023
@gdalle gdalle closed this as completed Jun 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants