Skip to content

Commit

Permalink
updates for julia 0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed May 7, 2018
1 parent 6f16bfb commit 7718c39
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ os:
- osx

julia:
- 0.6
# - 0.7
- nightly

matrix:
Expand Down
4 changes: 2 additions & 2 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
julia 0.6
julia 0.7-
JSON
BenchmarkTools
ProgressMeter
ProgressMeter
6 changes: 4 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
environment:
matrix:
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
# - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.7/julia-0.7-latest-win32.exe"
# - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.7/julia-0.7-latest-win64.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"

branches:
only:
Expand Down
6 changes: 3 additions & 3 deletions deps/build.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
if !isfile(joinpath(@__DIR__, "already_showed"))
print_with_color(Base.info_color(), STDERR,
printstyled(stderr,
"""
PkgBenchmark has been completely rewritten. Please see https://github.com/JuliaCI/PkgBenchmark.jl/
for updated documentation and examples. Code written for previous versions of PkgBenchmark is
unlikely to still work.
""")
"""; color = Base.info_color())
touch("already_showed")
end
end
2 changes: 1 addition & 1 deletion docs/src/run_benchmarks.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ BenchmarkConfig:
```

The `id` is a commit, branch etc as described in the previous section. An `id` with value `nothing` means that the current state of the package will be benchmarked.
The default value of `juliacmd` is `joinpath(JULIA_HOME, Base.julia_exename()` which is the command to run the julia executable without any command line arguments.
The default value of `juliacmd` is `joinpath(Sys.BINDIR, Base.julia_exename()` which is the command to run the julia executable without any command line arguments.

To instead benchmark the branch `PR`, using the julia command `julia -O3`
with the environment variable `JULIA_NUM_THREADS` set to `4`, the config would be created as
Expand Down
5 changes: 5 additions & 0 deletions src/PkgBenchmark.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ module PkgBenchmark
using BenchmarkTools
using JSON
using ProgressMeter
using Pkg
using LibGit2
using Dates
using InteractiveUtils
using Printf

export benchmarkpkg, judge, writeresults, readresults, export_markdown
export BenchmarkConfig, BenchmarkResults, BenchmarkJudgement
Expand Down
12 changes: 6 additions & 6 deletions src/benchmarkconfig.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ This includes the following:
* Custom environment variables (e.g. `JULIA_NUM_THREADS`).
"""
struct BenchmarkConfig
id::Union{String,Void}
id::Union{String,Nothing}
juliacmd::Cmd
env::Dict{String,Any}
end

"""
BenchmarkConfig(;id::Union{String, Void} = nothing,
juliacmd::Cmd = `joinpath(JULIA_HOME, Base.julia_exename())`,
BenchmarkConfig(;id::Union{String, Nothing} = nothing,
juliacmd::Cmd = `joinpath(Sys.BINDIR, Base.julia_exename())`,
env::Dict{String, Any} = Dict{String, Any}())
Creates a `BenchmarkConfig` from the following keyword arguments:
Expand All @@ -44,16 +44,16 @@ BenchmarkConfig:
env: JULIA_NUM_THREADS => 4
```
"""
function BenchmarkConfig(;id::Union{String,Void} = nothing,
function BenchmarkConfig(;id::Union{String,Nothing} = nothing,

juliacmd::Cmd = `$(joinpath(JULIA_HOME, Base.julia_exename()))`,
juliacmd::Cmd = `$(joinpath(Sys.BINDIR, Base.julia_exename()))`,
env::Dict = Dict{String,Any}())
BenchmarkConfig(id, juliacmd, env)
end

BenchmarkConfig(cfg::BenchmarkConfig) = cfg
BenchmarkConfig(str::String) = BenchmarkConfig(id = str)
BenchmarkConfig(::Void) = BenchmarkConfig()
BenchmarkConfig(::Nothing) = BenchmarkConfig()

function BenchmarkConfig(d::Dict)
BenchmarkConfig(
Expand Down
8 changes: 4 additions & 4 deletions src/benchmarkjudgement.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ function Base.show(io::IO, judgement::BenchmarkJudgement)
target, base = judgement.target_results, judgement.baseline_results
print(io, "Benchmarkjudgement (target / baseline):\n")
println(io, " Package: ", target.name)
println(io, " Dates: ", Base.Dates.format(target.date, "d u Y - H:M"), " / ",
Base.Dates.format(base.date, "d u Y - H:M"))
println(io, " Dates: ", Dates.format(target.date, "d u Y - H:M"), " / ",
Dates.format(base.date, "d u Y - H:M"))
println(io, " Package commits: ", target.commit[1:min(length(target.commit), 6)], " / ",
base.commit[1:min(length(base.commit), 6)])
println(io, " Julia commits: ", target.julia_commit[1:6], " / ",
Expand Down Expand Up @@ -66,8 +66,8 @@ function export_markdown(io::IO, judgement::BenchmarkJudgement)
## Job Properties
* Time of benchmarks:
- Target: $(Base.Dates.format(date(target), "d u Y - HH:MM"))
- Baseline: $(Base.Dates.format(date(baseline), "d u Y - HH:MM"))
- Target: $(Dates.format(date(target), "d u Y - HH:MM"))
- Baseline: $(Dates.format(date(baseline), "d u Y - HH:MM"))
* Package commits:
- Target: $(commit(target)[1:min(6, length(commit(target)))])
- Baseline: $(commit(baseline)[1:min(6, length(commit(baseline)))])
Expand Down
6 changes: 3 additions & 3 deletions src/benchmarkresults.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ juliacommit(results::BenchmarkResults) = results.julia_commit
benchmarkgroup(results::BenchmarkResults) = results.benchmarkgroup
date(results::BenchmarkResults) = results.date
benchmarkconfig(results::BenchmarkResults) = results.benchmarkconfig
Base.versioninfo(results::BenchmarkResults) = results.vinfo
InteractiveUtils.versioninfo(results::BenchmarkResults) = results.vinfo


function Base.show(io::IO, results::BenchmarkResults)
print(io, "Benchmarkresults:\n")
println(io, " Package: ", results.name)
println(io, " Date: ", Base.Dates.format(results.date, "d u Y - HH:MM"))
println(io, " Date: ", Dates.format(results.date, "d u Y - HH:MM"))
println(io, " Package commit: ", results.commit[1:min(length(results.commit), 6)])
println(io, " Julia commit: ", results.julia_commit[1:6])
iob = IOBuffer()
Expand Down Expand Up @@ -117,7 +117,7 @@ function export_markdown(io::IO, results::BenchmarkResults)
# Benchmark Report for *$(name(results))*
## Job Properties
* Time of benchmark: $(Base.Dates.format(date(results), "d u Y - H:M"))
* Time of benchmark: $(Dates.format(date(results), "d u Y - H:M"))
* Package commit: $(commit(results)[1:min(6, length(commit(results)))])
* Julia commit: $(juliacommit(results)[1:min(6, length(juliacommit(results)))])
* Julia command flags: $julia_command_flags
Expand Down
8 changes: 4 additions & 4 deletions src/runbenchmark.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function benchmarkpkg(
end

local results
results_local = _with_reqs(joinpath(dirname(script), "REQUIRE"), () -> info("Resolving dependencies for benchmark...")) do
results_local = _with_reqs(joinpath(dirname(script), "REQUIRE"), () -> @info("Resolving dependencies for benchmark...")) do
_withtemp(tempname()) do f
_benchinfo("Running benchmarks...")
_runbenchmark(script, f, target, tunefile; retune=retune, custom_loadpath = custom_loadpath)
Expand Down Expand Up @@ -123,7 +123,7 @@ end
function _runbenchmark(file::String, output::String, benchmarkconfig::BenchmarkConfig, tunefile::String;
retune=false, custom_loadpath = nothing)
color = Base.have_color ? "--color=yes" : "--color=no"
compilecache = "--compilecache=" * (Bool(Base.JLOptions().use_compilecache) ? "yes" : "no")
compilecache = "--compiled-modules=" * (Bool(Base.JLOptions().use_compiled_modules) ? "yes" : "no")
_file, _output, _tunefile, _custom_loadpath = map(escape_string, (file, output, tunefile, custom_loadpath))
codecov_option = Base.JLOptions().code_coverage
coverage = if codecov_option == 0
Expand All @@ -150,8 +150,8 @@ end
function _runbenchmark_local(file, output, tunefile, retune)
# Loading
include(file)
suite = if isdefined(Main, :SUITE)
Main.SUITE
suite = if @isdefined SUITE
SUITE
else
error("`SUITE` variable not found, make sure the BenchmarkGroup is named `SUITE`")
end
Expand Down
6 changes: 3 additions & 3 deletions src/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ end
_shastring(r::LibGit2.GitRepo, targetname) = string(LibGit2.revparseid(r, targetname))
_shastring(dir::AbstractString, targetname) = LibGit2.with(r -> _shastring(r, targetname), LibGit2.GitRepo(dir))

_benchinfo(str) = print_with_color(Base.info_color(), STDOUT, "PkgBenchmark: ", str, "\n")
_benchwarn(str) = print_with_color(Base.info_color(), STDOUT, "PkgBenchmark: ", str, "\n")
_benchinfo(str) = printstyled(stdout, "PkgBenchmark: ", str, "\n"; color = Base.info_color())
_benchwarn(str) = printstyled(stdout, "PkgBenchmark: ", str, "\n"; color = Base.info_color())

############
# Markdown #
############

_idrepr(id) = (str = repr(id); str[searchindex(str, '['):end])
_idrepr(id) = (str = repr(id); str[coalesce(findfirst(isequal('['), str), 0):end])
_intpercent(p) = string(ceil(Int, p * 100), "%")
_resultrow(ids, t::BenchmarkTools.Trial, col_widths) =
_resultrow(ids, minimum(t), col_widths)
Expand Down
15 changes: 9 additions & 6 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using PkgBenchmark
using BenchmarkTools
using Base.Test
using Test
using Dates
using LibGit2
using Random

const BENCHMARK_DIR = joinpath(@__DIR__, "..", "benchmark")

Expand Down Expand Up @@ -38,7 +41,7 @@ end
test_structure(PkgBenchmark.benchmarkgroup(results))
@test PkgBenchmark.name(results) == "PkgBenchmark"
@test Dates.Year(PkgBenchmark.date(results)) == Dates.Year(now())
export_markdown(STDOUT, results)
export_markdown(stdout, results)
end

const TEST_PACKAGE_NAME = "Example"
Expand All @@ -48,7 +51,7 @@ tmp_dir = joinpath(tempdir(), randstring())
old_pkgdir = Pkg.dir()

temp_pkg_dir(;tmp_dir = tmp_dir) do
test_sig = LibGit2.Signature("TEST", "[email protected]", round(time(), 0), 0)
test_sig = LibGit2.Signature("TEST", "[email protected]", round(time(); digits=0), 0)
Pkg.add(TEST_PACKAGE_NAME)

@testset "benchmarkconfig" begin
Expand All @@ -66,7 +69,7 @@ temp_pkg_dir(;tmp_dir = tmp_dir) do
print(file, str)
end

config = BenchmarkConfig(juliacmd = `$(joinpath(JULIA_HOME, Base.julia_exename())) -O3`,
config = BenchmarkConfig(juliacmd = `$(joinpath(Sys.BINDIR, Base.julia_exename())) -O3`,
env = Dict("JL_PKGBENCHMARK_TEST_ENV" => 10))
@test typeof(benchmarkpkg(TEST_PACKAGE_NAME, config, script=f; custom_loadpath=old_pkgdir)) == BenchmarkResults
end
Expand Down Expand Up @@ -113,7 +116,7 @@ temp_pkg_dir(;tmp_dir = tmp_dir) do
tmp = tempname() * ".json"

# Benchmark dirty repo
cp(joinpath(@__DIR__, "..", "benchmark", "benchmarks.jl"), joinpath(testpkg_path, "benchmark", "benchmarks.jl"); remove_destination=true)
cp(joinpath(@__DIR__, "..", "benchmark", "benchmarks.jl"), joinpath(testpkg_path, "benchmark", "benchmarks.jl"); force=true)
cp(joinpath(@__DIR__, "..", "benchmark", "REQUIRE"), joinpath(testpkg_path, "benchmark", "REQUIRE"))
LibGit2.add!(repo, "benchmark/benchmarks.jl")
LibGit2.add!(repo, "benchmark/REQUIRE")
Expand Down Expand Up @@ -145,7 +148,7 @@ temp_pkg_dir(;tmp_dir = tmp_dir) do
@testset "judging" begin
judgement = judge(TEST_PACKAGE_NAME, "HEAD~", "HEAD", custom_loadpath=old_pkgdir)
test_structure(PkgBenchmark.benchmarkgroup(judgement))
export_markdown(STDOUT, judgement)
export_markdown(stdout, judgement)
judgement = judge(TEST_PACKAGE_NAME, "HEAD", custom_loadpath=old_pkgdir)
test_structure(PkgBenchmark.benchmarkgroup(judgement))
end
Expand Down

0 comments on commit 7718c39

Please sign in to comment.