Skip to content

Conversation

@stevengj
Copy link
Contributor

@stevengj stevengj commented Jan 21, 2017

This PR adds two macros, @btime and @belapsed, that are drop-in replacements for @time and @elapsed from Base except that they use the @benchmark apparatus. For example:

julia> @btime sin(1)
  11.410 ns (0 allocations: 0 bytes)
0.8414709848078965
 
julia> @belapsed sin(1)
1.1412412412412412e-8

It also changes the memory output to use SI prefixes. Previously, it would output something like 17.34 kb, which is ambiguous — is a kb 1000 or 1024 bytes (we use 1024)? The SI ISQ prefix is "KiB" for kibibyte, which unambiguously means 1024 bytes.

Also, it now prints 24 bytes and not 24.00 bytes — the decimal point was confusing since (presumably) we will never be able to allocate a fractional number of bytes.

Closes #35.

@stevengj
Copy link
Contributor Author

Test failure in 0.6 is due to #38.

src/execution.jl Outdated
iters = 2
while (time() - start_time) < params.seconds && iters params.samples
params.gcsample && BenchmarkTools.gcscrub()
params.gcsample && BenchmarkTools.gcscrub()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this getting done twice here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo, sorry

@stevengj
Copy link
Contributor Author

Yay, tests are passing in the rebased branch.

@stevengj
Copy link
Contributor Author

Rebased.

@jrevels jrevels merged commit 208cb75 into master Jan 22, 2017
@jrevels jrevels deleted the btime branch January 22, 2017 17:50
@jrevels
Copy link
Member

jrevels commented Jan 22, 2017

Thanks!

@stevengj
Copy link
Contributor Author

See also JuliaLang/julia#20173

@KristofferC
Copy link
Contributor

@btime is awesome and something that I have wanted for a long time (without realizing it).

@@ -1,3 +1,3 @@
julia 0.4
Compat 0.8.0
Compat 0.9.5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this using from 0.9.5?

Copy link
Contributor Author

@stevengj stevengj Feb 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't remember, maybe it was the Symbol constructor? I definitely upgraded the Compat requirement for a reason.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Symbol is older I believe - probably JuliaLang/Compat.jl@2c11855

Maybe an earlier version of this was using one of the show rewrites? doesn't look like the final version is though

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think maybe an earlier version tried to use a buffer and String(take!(buf)) for the @btime test, which requires Compat 0.9.5. I then rewrote it to use redirect_stdout(f) with a temporary file, which requires Compat 0.9.0 (JuliaLang/Compat.jl@2c11855)

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.

provide analogue of @elapsed

5 participants