Skip to content

Commit

Permalink
Update benchmarks.jl (#156)
Browse files Browse the repository at this point in the history
* Update benchmarks.jl

update benchmarks to use BenchmarkGroup() syntax

* add REQUIRE to benchmarks

* update benchmarks instructions
  • Loading branch information
mforets authored and dpsanders committed Jun 29, 2018
1 parent 6dce3a9 commit e6e0d0d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
2 changes: 2 additions & 0 deletions benchmark/REQUIRE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BenchmarkTools 0.3.1
PkgBenchmark 0.1.1
46 changes: 25 additions & 21 deletions benchmark/benchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,49 @@
- results = benchmarkpkg("IntervalArithmetic")
- showall(results)
- results = judge("IntervalArithmetic", "v0.9.1") # compare current version to that tag
To compare the current version with a given release use `judge`:
- results = judge("IntervalArithmetic", tag)
- showall(results)
=#
To export the benchmark results to a markdown file, do:
using IntervalArithmetic
- export_markdown("results.md", results)
=#

@benchgroup "Constructors" begin
@bench "Interval" Interval(1, 2)
end
using BenchmarkTools, IntervalArithmetic

@benchgroup "@interval" begin
const SUITE = BenchmarkGroup() # parent BenchmarkGroup to contain our suite

@bench "@interval" @interval(0.1)
@bench "pi" @interval(pi)
@bench "expression" @interval(sin(0.1) + cos(0.2))
end
S = SUITE["Constructors"] = BenchmarkGroup()
S["Interval"] = @benchmarkable Interval(1, 2)

@benchgroup "Arithmetic" begin
S = SUITE["Intervals"] = BenchmarkGroup()
S["@interval"] = @benchmarkable @interval(0.1)
S["pi"] = @benchmarkable @interval(pi)
S["expression"] = @benchmarkable @interval(sin(0.1) + cos(0.2))

S = SUITE["Arithmetic"] = BenchmarkGroup()
begin
a = Interval(1, 2)
b = Interval(3, 4)

for op in (+, -, *, /)
@bench string(op) $(op)($a, $b)
S[string(op)] = @benchmarkable $(op)($a, $b)
end
end

@benchgroup "Elementary functions" begin
S = SUITE["Elementary functions"] = BenchmarkGroup()
begin
for op in (exp, log, sin, tan)
@bench string(op) $(op)($a)
S[string(op)] = @benchmarkable $(op)($a)
end
end

@benchgroup "Sum" begin

S = SUITE["Sum"] = BenchmarkGroup()
begin
sum1(N) = sum(Interval(i, i+1) for i in 1:N)
sum2(N) = (one = Interval(1.0); sum(one / (i^2) for i in 1:N) )

@bench "Sum1" sum1(1000)
@bench "Sum2" sum2(1000)
sum2(N) = (one = Interval(1.0); sum(one / (i^2) for i in 1:N))
S["Sum1"] = @benchmarkable sum1(1000)
S["Sum2"] = @benchmarkable sum2(1000)
end

0 comments on commit e6e0d0d

Please sign in to comment.