Skip to content

Commit

Permalink
deprecate interactive save prompt (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC committed Jul 20, 2017
1 parent 034b8d8 commit 8b056cb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
36 changes: 22 additions & 14 deletions src/runbenchmark.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ defaulttunefile(pkg) =
saveresults=true,
tunefile=defaulttunefile(pkg),
retune=false,
promptsave=true,
promptoverwrite=true)
overwrite=true)
**Arguments**:
Expand All @@ -82,11 +81,9 @@ defaulttunefile(pkg) =
* `require` is the REQUIRE file containing dependencies needed for the benchmark. Defaults to `PKG/benchmark/REQUIRE`.
* `resultsdir` the directory where to file away results. Defaults to `PKG/benchmark/.results`. Provided the repository is not dirty, results generated will be saved in this directory in a file named `<SHA1_of_commit>.jld`. And can be used later by functions such as `judge`. If you choose to, you can save the results manually using `writeresults(file, results)` where `results` is the return value of `benchmarkpkg` function. It can be read back with `readresults(file)`.
* `saveresults` if set to false, results will not be saved in `resultsdir`.
* `promptsave` if set to false, you will prompted to confirm before saving the results.
* `tunefile` file to use for tuning benchmarks, will be created if doesn't exist. Defaults to `PKG/benchmark/.tune.jld`
* `retune` force a re-tune, saving results to the tune file
* `promptsave` if set to false, you will prompted to confirm before saving the results.
* `promptoverwrite` if set to false, will not asked to confirm before overwriting previously saved results for a commit.
* `overwrite` overwrites the result file if it already exists
**Returns:**
Expand All @@ -110,9 +107,11 @@ function benchmarkpkg(pkg, ref=nothing;
tunefile=defaulttunefile(pkg),
retune=false,
saveresults=true,
promptsave=true,
promptoverwrite=true,
custom_loadpath="" #= used in tests =#)
overwrite=true,
custom_loadpath="", #= used in tests =#
promptsave=nothing #= deprecated =#)

promptsave != nothing && Base.warn_once("the `promptsave` keyword is deprecated and will be removed.")

function do_benchmark()
!isfile(script) && error("Benchmark script $script not found")
Expand All @@ -129,16 +128,25 @@ function benchmarkpkg(pkg, ref=nothing;

if !dirty
if saveresults
tosave = if promptsave
tosave = true
if promptsave == true
print("File results of this run? (commit=$(sha[1:6]), resultsdir=$resultsdir) (Y/n) ")
response = readline() |> strip
response == "" || lowercase(response) == "y"
else true end
response = string(readline())
tosave = if response == "" || lowercase(response) == "y"
true
else
false
end
end
if tosave
!isdir(resultsdir) && mkpath(resultsdir)
resfile = joinpath(resultsdir, sha*".jld")
writeresults(resfile, res)
info("Results of the benchmark were written to $resfile")
if !isfile(resfile) || overwrite == true
writeresults(resfile, res)
info("Results of the benchmark were written to $resfile")
else
info("Found existing results, no output written")
end
end
end
else
Expand Down
10 changes: 5 additions & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ temp_pkg_dir(;tmp_dir = tmp_dir) do
# Test we are on a branch and run benchmark on a commit that we end up back on the branch
LibGit2.branch!(repo, "PR")
LibGit2.branch!(repo, "master")
PkgBenchmark.benchmarkpkg(TEST_PACKAGE_NAME, "PR"; custom_loadpath=old_pkgdir, promptsave=false)
PkgBenchmark.benchmarkpkg(TEST_PACKAGE_NAME, "PR"; custom_loadpath=old_pkgdir)
@test LibGit2.branch(repo) == "master"

# Test we are on a commit and run benchmark on another commit and end up on the commit
LibGit2.checkout!(repo, string(commit_master))
PkgBenchmark.benchmarkpkg(TEST_PACKAGE_NAME, "PR"; custom_loadpath=old_pkgdir, promptsave=false)
PkgBenchmark.benchmarkpkg(TEST_PACKAGE_NAME, "PR"; custom_loadpath=old_pkgdir)
@test LibGit2.revparseid(repo, "HEAD") == commit_master
end

Expand All @@ -105,7 +105,7 @@ temp_pkg_dir(;tmp_dir = tmp_dir) do
commitid = LibGit2.commit(repo, "commiting full benchmarks and REQUIRE"; author=test_sig, committer=test_sig)
resfile = joinpath(tmp, "$(string(commitid)).jld")
@test !LibGit2.isdirty(repo)
results = PkgBenchmark.benchmarkpkg(TEST_PACKAGE_NAME, "HEAD"; custom_loadpath=old_pkgdir, promptsave=false, resultsdir=tmp)
results = PkgBenchmark.benchmarkpkg(TEST_PACKAGE_NAME, "HEAD"; custom_loadpath=old_pkgdir, resultsdir=tmp)
test_structure(results)
@test isfile(resfile)
@test PkgBenchmark.readresults(resfile) == results
Expand All @@ -116,12 +116,12 @@ temp_pkg_dir(;tmp_dir = tmp_dir) do
LibGit2.commit(repo, "dummy commit"; author=test_sig, committer=test_sig)

@testset "withresults" begin
PkgBenchmark.withresults(TEST_PACKAGE_NAME, ["HEAD~", "HEAD"], custom_loadpath=old_pkgdir, promptsave=false) do res
PkgBenchmark.withresults(TEST_PACKAGE_NAME, ["HEAD~", "HEAD"], custom_loadpath=old_pkgdir) do res
@test length(res) == 2
a, b = res
test_structure(a)
test_structure(b)
test_structure(judge(minimum(a), minimum(b)))
end
end
end
end

0 comments on commit 8b056cb

Please sign in to comment.