Skip to content

Commit 5826243

Browse files
authored
Updates for 0.7/1.0 (#114)
Also remove `showall`, which was removed from Base, as well as the dependency on Compat
1 parent 55893ef commit 5826243

15 files changed

+79
-127
lines changed

.travis.yml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,20 @@ os:
44
- linux
55
- osx
66
julia:
7-
- 0.6
87
- 0.7
8+
- 1.0
99
- nightly
1010
notifications:
1111
email: false
12-
script:
13-
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
14-
- julia -e 'Pkg.clone(pwd()); Pkg.build("BenchmarkTools"); Pkg.test("BenchmarkTools"; coverage=true)'
12+
#script:
13+
# - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
14+
# - julia -e 'Pkg.clone(pwd()); Pkg.build("BenchmarkTools"); Pkg.test("BenchmarkTools"; coverage=true)'
1515
after_success:
16-
- julia -e 'cd(Pkg.dir("BenchmarkTools")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
16+
- |
17+
julia -e '
18+
import BenchmarkTools, Pkg
19+
Pkg.add("Coverage")
20+
using Coverage
21+
cd(normpath(dirname(pathof(BenchmarkTools)), ".."))
22+
Coveralls.submit(Coveralls.process_folder())
23+
'

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ If you're benchmarking on Linux, I wrote up a series of [tips and tricks](https:
3434
The simplest usage is via the [`@btime` macro](https://github.com/JuliaCI/BenchmarkTools.jl/blob/master/doc/manual.md#benchmarking-basics), which is analogous to Julia's built-in [`@time` macro](https://docs.julialang.org/en/stable/stdlib/base/#Base.@time) but is often more accurate (by collecting results over multiple runs):
3535

3636
```julia
37-
julia> using BenchmarkTools, Compat # you need to use both modules
37+
julia> using BenchmarkTools
3838

3939
julia> @btime sin(1)
4040
15.081 ns (0 allocations: 0 bytes)

REQUIRE

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
julia 0.6
2-
Compat 0.62.0
1+
julia 0.7
32
JSON

appveyor.yml

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
environment:
22
matrix:
3-
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
4-
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
5-
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
6-
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
3+
- julia_version: 0.7
4+
- julia_version: 1.0
5+
- julia_version: latest
6+
7+
platform:
8+
- x86 # 32-bit
9+
- x64 # 64-bit
10+
11+
# # Uncomment the following lines to allow failures on nightly julia
12+
# # (tests will run but not make your overall status red)
13+
# matrix:
14+
# allow_failures:
15+
# - julia_version: latest
716

817
branches:
918
only:
@@ -17,19 +26,18 @@ notifications:
1726
on_build_status_changed: false
1827

1928
install:
20-
- ps: "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
21-
# Download most recent Julia Windows binary
22-
- ps: (new-object net.webclient).DownloadFile(
23-
$env:JULIA_URL,
24-
"C:\projects\julia-binary.exe")
25-
# Run installer silently, output to C:\projects\julia
26-
- C:\projects\julia-binary.exe /S /D=C:\projects\julia
29+
- ps: iex ((new-object net.webclient).DownloadString("https://raw.githubusercontent.com/JuliaCI/Appveyor.jl/version-1/bin/install.ps1"))
2730

2831
build_script:
29-
# Need to convert from shallow to complete for Pkg.clone to work
30-
- IF EXIST .git\shallow (git fetch --unshallow)
31-
- C:\projects\julia\bin\julia -e "versioninfo();
32-
Pkg.clone(pwd(), \"BenchmarkTools\"); Pkg.build(\"BenchmarkTools\")"
32+
- echo "%JL_BUILD_SCRIPT%"
33+
- C:\julia\bin\julia -e "%JL_BUILD_SCRIPT%"
3334

3435
test_script:
35-
- C:\projects\julia\bin\julia --check-bounds=yes -e "Pkg.test(\"BenchmarkTools\")"
36+
- echo "%JL_TEST_SCRIPT%"
37+
- C:\julia\bin\julia -e "%JL_TEST_SCRIPT%"
38+
39+
# # Uncomment to support code coverage upload. Should only be enabled for packages
40+
# # which would have coverage gaps without running on Windows
41+
# on_success:
42+
# - echo "%JL_CODECOV_SCRIPT%"
43+
# - C:\julia\bin\julia -e "%JL_CODECOV_SCRIPT%"

doc/manual.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ end
526526
Let's look at our newly defined suite in the REPL:
527527

528528
```julia
529-
julia> showall(suite)
529+
julia> suite
530530
2-element BenchmarkTools.BenchmarkGroup:
531531
tags: []
532532
"utf8" => 2-element BenchmarkTools.BenchmarkGroup:
@@ -640,7 +640,7 @@ julia> g = BenchmarkGroup([], # no tags in the parent
640640
"a" => BenchmarkGroup(["1", "2", "3"], # contains tags and child groups
641641
"d" => BenchmarkGroup(["8"], 1 => 1),
642642
"e" => BenchmarkGroup(["9"], 2 => 2)));
643-
julia> showall(g)
643+
julia> g
644644
BenchmarkTools.BenchmarkGroup:
645645
tags: []
646646
"c" => BenchmarkTools.BenchmarkGroup:
@@ -678,7 +678,7 @@ To demonstrate the last two points:
678678

679679
```julia
680680
# also could've used `@tagged "1"`, `@tagged "a"`, `@tagged "e" || "d"`
681-
julia> showall(g[@tagged "8" || "9"])
681+
julia> g[@tagged "8" || "9"]
682682
BenchmarkTools.BenchmarkGroup:
683683
tags: []
684684
"a" => BenchmarkTools.BenchmarkGroup:
@@ -690,7 +690,7 @@ BenchmarkTools.BenchmarkGroup:
690690
tags: ["8"]
691691
1 => 1
692692

693-
julia> showall(g[@tagged "d"])
693+
julia> g[@tagged "d"]
694694
BenchmarkTools.BenchmarkGroup:
695695
tags: []
696696
"a" => BenchmarkTools.BenchmarkGroup:
@@ -699,7 +699,7 @@ BenchmarkTools.BenchmarkGroup:
699699
tags: ["8"]
700700
1 => 1
701701

702-
julia> showall(g[@tagged "9"])
702+
julia> g[@tagged "9"]
703703
BenchmarkTools.BenchmarkGroup:
704704
tags: []
705705
"a" => BenchmarkTools.BenchmarkGroup:
@@ -714,7 +714,7 @@ BenchmarkTools.BenchmarkGroup:
714714
It's sometimes useful to create `BenchmarkGroup` where the keys are drawn from one `BenchmarkGroup`, but the values are drawn from another. You can accomplish this by indexing into the latter `BenchmarkGroup` with the former:
715715

716716
```julia
717-
julia> showall(g) # leaf values are integers
717+
julia> g # leaf values are integers
718718
BenchmarkTools.BenchmarkGroup:
719719
tags: []
720720
"c" => BenchmarkTools.BenchmarkGroup:
@@ -738,7 +738,7 @@ BenchmarkTools.BenchmarkGroup:
738738
"2" => 2
739739
"3" => 3
740740

741-
julia> showall(x) # note that leaf values are characters
741+
julia> x # note that leaf values are characters
742742
BenchmarkTools.BenchmarkGroup:
743743
tags: []
744744
"c" => BenchmarkTools.BenchmarkGroup:
@@ -754,7 +754,7 @@ BenchmarkTools.BenchmarkGroup:
754754
"2" => '2'
755755
"3" => '3'
756756

757-
julia> showall(g[x]) # index into `g` with the keys of `x`
757+
julia> g[x] # index into `g` with the keys of `x`
758758
BenchmarkTools.BenchmarkGroup:
759759
tags: []
760760
"c" => BenchmarkTools.BenchmarkGroup:
@@ -788,7 +788,7 @@ To solve this problem, BenchmarkTools allows you to uniquely index group nodes u
788788
```julia
789789
julia> g = BenchmarkGroup([], 1 => BenchmarkGroup([], "a" => BenchmarkGroup([], :b => 1234)));
790790

791-
julia> showall(g)
791+
julia> g
792792
BenchmarkTools.BenchmarkGroup:
793793
tags: []
794794
1 => BenchmarkTools.BenchmarkGroup:
@@ -797,17 +797,17 @@ BenchmarkTools.BenchmarkGroup:
797797
tags: []
798798
:b => 1234
799799

800-
julia> showall(g[[1]]) # == g[1]
800+
julia> g[[1]] # == g[1]
801801
BenchmarkTools.BenchmarkGroup:
802802
tags: []
803803
"a" => BenchmarkTools.BenchmarkGroup:
804804
tags: []
805805
:b => 1234
806-
julia> showall(g[[1, "a"]]) # == g[1]["a"]
806+
julia> g[[1, "a"]] # == g[1]["a"]
807807
BenchmarkTools.BenchmarkGroup:
808808
tags: []
809809
:b => 1234
810-
julia> showall(g[[1, "a", :b]]) # == g[1]["a"][:b]
810+
julia> g[[1, "a", :b]] # == g[1]["a"][:b]
811811
1234
812812
```
813813

@@ -817,7 +817,7 @@ Keep in mind that this indexing scheme also works with `setindex!`:
817817
julia> g[[1, "a", :b]] = "hello"
818818
"hello"
819819

820-
julia> showall(g)
820+
julia> g
821821
BenchmarkTools.BenchmarkGroup:
822822
tags: []
823823
1 => BenchmarkTools.BenchmarkGroup:
@@ -833,7 +833,7 @@ Assigning into a `BenchmarkGroup` with a `Vector` creates sub-groups as necessar
833833
julia> g[[2, "a", :b]] = "hello again"
834834
"hello again"
835835

836-
julia> showall(g)
836+
julia> g
837837
2-element BenchmarkTools.BenchmarkGroup:
838838
tags: []
839839
2 => 1-element BenchmarkTools.BenchmarkGroup:

src/BenchmarkTools.jl

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
1-
__precompile__()
2-
31
module BenchmarkTools
42

5-
using Compat
63
using JSON
74
using Base.Iterators
85

9-
if VERSION >= v"0.7.0-beta.85"
10-
import Statistics: mean, median
11-
else
12-
import Base: mean, median
13-
end
14-
15-
using Compat.Printf
6+
using Statistics
7+
using Printf
168

179

1810
const BENCHMARKTOOLS_VERSION = v"0.2.2"

src/execution.jl

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
# Trigger several successive GC sweeps. This is more comprehensive than running just a
22
# single sweep, since freeable objects may need more than one sweep to be appropriately
33
# marked and freed.
4-
if VERSION >= v"0.7.0-DEV.3469"
5-
gcscrub() = (GC.gc(); GC.gc(); GC.gc(); GC.gc())
6-
else
7-
gcscrub() = (gc(); gc(); gc(); gc())
8-
end
4+
gcscrub() = (GC.gc(); GC.gc(); GC.gc(); GC.gc())
95

106
#############
117
# Benchmark #
@@ -33,25 +29,8 @@ end
3329
# compatiblity hacks #
3430
######################
3531

36-
if VERSION >= v"0.7.0-DEV.1139"
37-
run_result(b::Benchmark, p::Parameters = b.params; kwargs...) = Base.invokelatest(_run, b, p; kwargs...)
38-
lineartrial(b::Benchmark, p::Parameters = b.params; kwargs...) = Base.invokelatest(_lineartrial, b, p; kwargs...)
39-
elseif VERSION < v"0.7.0-DEV.484"
40-
# `invokelatest` on v0.6 doesn't take keyword arguments, so we fall back
41-
# to the `current_module` approach if we're on a Julia version where that's
42-
# still possible.
43-
function run_result(b::Benchmark, p::Parameters = b.params; kwargs...)
44-
return Core.eval(@__MODULE__, :(BenchmarkTools._run($(b), $(p); $(kwargs...))))
45-
end
46-
function lineartrial(b::Benchmark, p::Parameters = b.params; kwargs...)
47-
return Core.eval(@__MODULE__, :(BenchmarkTools._lineartrial($(b), $(p); $(kwargs...))))
48-
end
49-
else
50-
# There's a commit gap between `current_module` deprecation and `invokelatest` keyword
51-
# argument support. I could try to hack something together just for that gap, but it's
52-
# probably not worth it.
53-
error("Congratulations, you've found the obscure range of Julia v0.7-dev commits where BenchmarkTools is really, really broken. Sorry about that :(")
54-
end
32+
run_result(b::Benchmark, p::Parameters = b.params; kwargs...) = Base.invokelatest(_run, b, p; kwargs...)
33+
lineartrial(b::Benchmark, p::Parameters = b.params; kwargs...) = Base.invokelatest(_lineartrial, b, p; kwargs...)
5534

5635
#############
5736
# execution #
@@ -274,11 +253,9 @@ macro benchmarkable(args...)
274253
core_vars = isa(core, Expr) ? collectvars(core) : []
275254
out_vars = filter(var -> var in setup_vars, core_vars)
276255

277-
eval_module = VERSION >= v"0.7.0-DEV.484" ? __module__ : current_module()
278-
279256
# generate the benchmark definition
280257
return esc(quote
281-
$BenchmarkTools.generate_benchmark_definition($(eval_module),
258+
$BenchmarkTools.generate_benchmark_definition($__module__,
282259
$(Expr(:quote, out_vars)),
283260
$(Expr(:quote, setup_vars)),
284261
$(Expr(:quote, core)),

src/groups.jl

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ end
1919
# Dict-like methods #
2020
#-------------------#
2121

22-
if VERSION < v"0.7.0-DEV.2731"
23-
const empty = similar
24-
end
25-
2622
Base.:(==)(a::BenchmarkGroup, b::BenchmarkGroup) = a.tags == b.tags && a.data == b.data
2723
Base.copy(group::BenchmarkGroup) = BenchmarkGroup(copy(group.tags), copy(group.data))
2824
Base.similar(group::BenchmarkGroup) = BenchmarkGroup(copy(group.tags), empty(group.data))
@@ -34,9 +30,7 @@ Base.delete!(group::BenchmarkGroup, k...) = delete!(group.data, k...)
3430
Base.haskey(group::BenchmarkGroup, k) = haskey(group.data, k)
3531
Base.keys(group::BenchmarkGroup) = keys(group.data)
3632
Base.values(group::BenchmarkGroup) = values(group.data)
37-
Base.start(group::BenchmarkGroup) = start(group.data)
38-
Base.next(group::BenchmarkGroup, state) = next(group.data, state)
39-
Base.done(group::BenchmarkGroup, state) = done(group.data, state)
33+
Base.iterate(group::BenchmarkGroup, i=1) = iterate(group.data, i)
4034

4135
# mapping/filtering #
4236
#-------------------#
@@ -60,12 +54,7 @@ end
6054
mapvals!(f, group::BenchmarkGroup) = mapvals!(f, similar(group), group)
6155
mapvals(f, groups::BenchmarkGroup...) = mapvals!(f, similar(first(groups)), groups...)
6256

63-
if VERSION >= v"0.7.0-DEV.1393"
64-
filtervals!(f, group::BenchmarkGroup) = (filter!(kv -> f(kv[2]), group.data); return group)
65-
else
66-
filtervals!(f, group::BenchmarkGroup) = (filter!((k, v) -> f(v), group.data); return group)
67-
end
68-
57+
filtervals!(f, group::BenchmarkGroup) = (filter!(kv -> f(kv[2]), group.data); return group)
6958
filtervals(f, group::BenchmarkGroup) = filtervals!(f, copy(group))
7059

7160
Base.filter!(f, group::BenchmarkGroup) = (filter!(f, group.data); return group)
@@ -76,8 +65,8 @@ Base.filter(f, group::BenchmarkGroup) = filter!(f, copy(group))
7665

7766
Base.minimum(group::BenchmarkGroup) = mapvals(minimum, group)
7867
Base.maximum(group::BenchmarkGroup) = mapvals(maximum, group)
79-
mean(group::BenchmarkGroup) = mapvals(mean, group)
80-
median(group::BenchmarkGroup) = mapvals(median, group)
68+
Statistics.mean(group::BenchmarkGroup) = mapvals(mean, group)
69+
Statistics.median(group::BenchmarkGroup) = mapvals(median, group)
8170
Base.min(groups::BenchmarkGroup...) = mapvals(min, groups...)
8271
Base.max(groups::BenchmarkGroup...) = mapvals(max, groups...)
8372

@@ -259,8 +248,6 @@ Base.setindex!(group::BenchmarkGroup, v, k::BenchmarkGroup) = error("A Benchmark
259248

260249
tagrepr(tags) = string("[", join(map(repr, tags), ", "), "]")
261250

262-
Base.showall(io::IO, group::BenchmarkGroup) = show(io, MIME"text/plain"(), group; verbose = true, limit = Inf)
263-
264251
Base.show(io::IO, group::BenchmarkGroup) = print(io, "$(length(group))-element BenchmarkGroup($(tagrepr(group.tags)))")
265252

266253
function Base.show(io::IO, mime::MIME"text/plain", group::BenchmarkGroup, pad = ""; verbose = false, limit = 10)

src/serialization.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using Base.Meta: parse
2-
31
const VERSIONS = Dict("Julia" => string(VERSION),
42
"BenchmarkTools" => string(BENCHMARKTOOLS_VERSION))
53

@@ -24,7 +22,7 @@ function recover(x::Vector)
2422
length(x) == 2 || throw(ArgumentError("Expecting a vector of length 2"))
2523
typename = x[1]::String
2624
fields = x[2]::Dict
27-
T = Core.eval(@__MODULE__, parse(typename))::Type
25+
T = Core.eval(@__MODULE__, Meta.parse(typename))::Type
2826
fc = fieldcount(T)
2927
xs = Vector{Any}(undef, fc)
3028
for i = 1:fc
@@ -71,9 +69,9 @@ function save(io::IO, args...)
7169
goodargs = Any[]
7270
for arg in args
7371
if arg isa String
74-
Compat.@warn("Naming variables in serialization is no longer supported.\n" *
75-
"The name will be ignored and the object will be serialized " *
76-
"in the order it appears in the input.")
72+
@warn("Naming variables in serialization is no longer supported.\n" *
73+
"The name will be ignored and the object will be serialized " *
74+
"in the order it appears in the input.")
7775
continue
7876
elseif !any(T->arg isa T, SUPPORTED_TYPES)
7977
throw(ArgumentError("Only BenchmarkTools types can be serialized."))

src/trials.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ end
3939
Base.length(t::Trial) = length(t.times)
4040
Base.getindex(t::Trial, i::Number) = push!(Trial(t.params), t.times[i], t.gctimes[i], t.memory, t.allocs)
4141
Base.getindex(t::Trial, i) = Trial(t.params, t.times[i], t.gctimes[i], t.memory, t.allocs)
42-
Compat.lastindex(t::Trial) = length(t)
42+
Base.lastindex(t::Trial) = length(t)
4343

4444
function Base.sort!(t::Trial)
4545
inds = sortperm(t.times)
@@ -118,8 +118,8 @@ function Base.maximum(trial::Trial)
118118
return TrialEstimate(trial, trial.times[i], trial.gctimes[i])
119119
end
120120

121-
median(trial::Trial) = TrialEstimate(trial, median(trial.times), median(trial.gctimes))
122-
mean(trial::Trial) = TrialEstimate(trial, mean(trial.times), mean(trial.gctimes))
121+
Statistics.median(trial::Trial) = TrialEstimate(trial, median(trial.times), median(trial.gctimes))
122+
Statistics.mean(trial::Trial) = TrialEstimate(trial, mean(trial.times), mean(trial.gctimes))
123123

124124
Base.isless(a::TrialEstimate, b::TrialEstimate) = isless(time(a), time(b))
125125

0 commit comments

Comments
 (0)