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 optional description to @time and new @showtime macro #42431

Merged
merged 3 commits into from
Oct 25, 2021

Conversation

IanButterworth
Copy link
Sponsor Member

@IanButterworth IanButterworth commented Sep 30, 2021

Adds an optional description to @time and @timev, and a new @showtime macro that is supposed to mimic the way @show prints the expr being evaluated first.

Intends to optionally make it a little easier to associate time reports with their source when the macros are used in multiple places

julia> @time sleep(0.2)
  0.204988 seconds (5 allocations: 144 bytes)

julia> @time "Sleep for a bit" sleep(0.2)
Sleep for a bit ->  0.203607 seconds (5 allocations: 144 bytes)

julia> for loop in 1:3
			@time loop sleep(0.2)
		end
1 ->  0.205158 seconds (5 allocations: 144 bytes)
2 ->  0.203381 seconds (5 allocations: 144 bytes)
3 ->  0.203496 seconds (5 allocations: 144 bytes)

julia> function foo() # a function where you don't know which order the @time's will print
		@sync begin
			  @async @time "first async" sleep(rand())
			  @async @time "second async" sleep(rand())
		end
		return
	   end

julia> foo()
second async ->  0.797018 seconds (5 allocations: 144 bytes)
first async ->  0.902320 seconds (12.01 k allocations: 577.507 KiB, 1.49% compilation time)

julia> @showtime sleep(0.2)
sleep(0.2) ->  0.205479 seconds (5 allocations: 144 bytes)

Also, there might be a better print format than message -> 0.797018 seconds (5 allocations: 144 bytes) but I couldn't think of one that wouldn't be more confusing

base/timing.jl Show resolved Hide resolved
@IanButterworth
Copy link
Sponsor Member Author

IanButterworth commented Oct 25, 2021

Maybe @showtime isn't quite the right name? It does mimic the LHS of @show, but it doesn't show the object value, so that might be confusing?

@reprtime?

Edit: I think it's fine.. It's like @show but for @time

@IanButterworth IanButterworth merged commit 5ecf5fc into JuliaLang:master Oct 25, 2021
@IanButterworth IanButterworth deleted the ib/time_messaging branch October 25, 2021 19:29
@JeffBezanson
Copy link
Sponsor Member

it's showtime

@timholy
Copy link
Sponsor Member

timholy commented Oct 27, 2021

If we're expanding the @show family...should we add @showln? https://github.com/timholy/DebuggingUtilities.jl#showln
It's not widely used, I think, but it's perhaps because you actually have to make that package a dependency of whatever you're debugging. If it's in Base, problem goes away.

We could also make it @show line=true expr and save an export.

@JeffBezanson
Copy link
Sponsor Member

I think the arrow (->) is a bit strange here; maybe a colon instead?

@IanButterworth
Copy link
Sponsor Member Author

Like this? Note that I also removed a 2nd lpad space on the time output after the :

julia> @showtime repeat("beetlejuice", 2)
repeat("beetlejuice", 2) : 0.000002 seconds (1 allocation: 40 bytes)
"beetlejuicebeetlejuice"

@IanButterworth
Copy link
Sponsor Member Author

@JeffBezanson @fredrikekre if the above looks good to you I'll PR it

@IanButterworth
Copy link
Sponsor Member Author

Formatting updated in #43255

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

Successfully merging this pull request may close these issues.

None yet

4 participants