Skip to content

Commit

Permalink
Merge pull request #7 from JuliaArrays/time
Browse files Browse the repository at this point in the history
Add `btime` options
  • Loading branch information
JeffFessler authored Feb 2, 2022
2 parents 399d611 + a0bab2e commit 98a0dc7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: CI
on:
push:
branches:
- main
paths-ignore:
- '*/*.md'
- 'docs/**'
Expand All @@ -17,7 +19,9 @@ jobs:
fail-fast: false
matrix:
version:
- '1.6'
- '1'
- 'nightly'
os:
- ubuntu-latest
- macOS-latest
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "LazyGrids"
uuid = "7031d0ef-c40d-4431-b2f8-61a8d2f650db"
authors = ["Sheehan Olver <[email protected]>", "Jeff Fessler <[email protected]>"]
version = "0.2.0"
version = "0.2.1"

[deps]
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Expand Down
14 changes: 8 additions & 6 deletions src/timer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ end


"""
btime()
btime(t ; unit::Symbol, digits::Int)
Pretty-print the @benchmark output for non-interactive use with Literate.
Returns a string so that Literate will capture the output.
* `unit` is `:ms` by default, for reporting in ms. Or use `μs`.
* `digits` is 1 by default.
"""
btime(t) = string(
"time=", round(median(t.times)/10^6, digits=1), # median time in ms
"ms mem=", t.memory,
" alloc=", t.allocs,
)
function btime(t ; unit::Symbol = :ms, digits::Int = 1)
scale = unit == :ms ? 10^6 : unit == :μs ? 10^3 : throw("unit $unit")
time = round(median(t.times)/scale; digits) # median time in units
string("time=", time, unit, " mem=", t.memory, " alloc=", t.allocs)
end
8 changes: 4 additions & 4 deletions test/timer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ using BenchmarkTools: @benchmark
using Test: @test, @testset, @test_throws, @inferred

@testset "timer" begin
t = @benchmark sum(1:7)
@inferred btime(t)
@test btime(t) isa String
t = @benchmark sum(1:7)
@inferred btime(t)
@test btime(t) isa String

@test (@timeo sum(1:7)) isa String
@test (@timeo sum(1:7)) isa String
end

2 comments on commit 98a0dc7

@JeffFessler
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@JuliaRegistrator() register

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/53656

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.1 -m "<description of version>" 98a0dc74dcae978020011160eeec4b1e2a37874a
git push origin v0.2.1

Please sign in to comment.