Skip to content

Commit 0c76318

Browse files
committed
Add benchmarking and data
1 parent c9f0305 commit 0c76318

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

perf/slopes.jl

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using BenchmarkTools, Compat, DataFrames, IntervalRootFinding, IntervalArithmetic, StaticArrays
2+
3+
function benchmark_results()
4+
f = [] # Example functions from Dietmar Ratz - An Optimized Interval Slope Arithmetic and its Application
5+
push!(f, x->((x + sin(x)) * exp(-x^2)))
6+
push!(f, x->(x^4 - 10x^3 + 35x^2 - 50x + 24))
7+
push!(f, x->((log(x + 1.25) - 0.84x) ^ 2))
8+
push!(f, x->(0.02x^2 - 0.03exp(-(20(x - 0.875))^2)))
9+
push!(f, x->(exp(x^2)))
10+
push!(f, x->(x^4 - 12x^3 + 47x^2 - 60x - 20exp(-x)))
11+
push!(f, x->(x^6 - 15x^4 + 27x^2 + 250))
12+
df = DataFrame()
13+
df[:Method] = ["Automatic Differentiation", "Slope Expansion"]
14+
for n in 1:length(f)
15+
16+
t1 = ForwardDiff.derivative(f[n], 0.75..1.75)
17+
t2 = slope(f[n], 0.75..1.75, 1.25)
18+
df[Symbol("f" * "$n")] = [t1, t2]
19+
end
20+
a = []
21+
for i in 1:length(f)
22+
push!(a, Symbol("f" * "$i"))
23+
end
24+
df1 = stack(df, a)
25+
dfnew = unstack(df1, :variable, :Method, :value)
26+
dfnew = rename(dfnew, :variable => :Function)
27+
println(dfnew)
28+
dfnew
29+
end
30+
31+
function benchmark_time()
32+
f = []
33+
push!(f, x->((x + sin(x)) * exp(-x^2)))
34+
push!(f, x->(x^4 - 10x^3 + 35x^2 - 50x + 24))
35+
push!(f, x->((log(x + 1.25) - 0.84x) ^ 2))
36+
push!(f, x->(0.02x^2 - 0.03exp(-(20(x - 0.875))^2)))
37+
push!(f, x->(exp(x^2)))
38+
push!(f, x->(x^4 - 12x^3 + 47x^2 - 60x - 20exp(-x)))
39+
push!(f, x->(x^6 - 15x^4 + 27x^2 + 250))
40+
df = DataFrame()
41+
df[:Method] = ["Automatic Differentiation", "Slope Expansion"]
42+
for n in 1:length(f)
43+
44+
t1 = @belapsed ForwardDiff.derivative($f[$n], 0.75..1.75)
45+
t2 = @belapsed slope($f[$n], 0.75..1.75, 1.25)
46+
df[Symbol("f" * "$n")] = [t1, t2]
47+
end
48+
a = []
49+
for i in 1:length(f)
50+
push!(a, Symbol("f" * "$i"))
51+
end
52+
df1 = stack(df, a)
53+
dfnew = unstack(df1, :variable, :Method, :value)
54+
dfnew = rename(dfnew, :variable => :Function)
55+
println(dfnew)
56+
dfnew
57+
end

perf/slopes_tabular.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Results
2+
3+
│ Row │ Function │ Automatic Differentiation │ Slope Expansion │
4+
├─────┼──────────┼───────────────────────────┼───────────────────────┤
5+
│ 1 │ f1 │ [-5.44573, 0.886249] │ [-2.79917, 0.0521429] │
6+
│ 2 │ f2 │ [-87.6875, 77.0625] │ [-43.875, 38.25] │
7+
│ 3 │ f3 │ [-0.474861, 0.787211] │ [-0.159199, 0.432842] │
8+
│ 4 │ f4 │ [-2.97001, 21.0701] │ [0.04, 0.326667] │
9+
│ 5 │ f5 │ [2.63258, 74.8333] │ [6.03135, 33.2205] │
10+
│ 6 │ f6 │ [-94.5871, 115.135] │ [-38.9908, 65.5595] │
11+
│ 7 │ f7 │ [-279.639, 167.667] │ [-146.852, 67.0665] │
12+
13+
Time
14+
15+
│ Row │ Function │ Automatic Differentiation │ Slope Expansion │
16+
├─────┼──────────┼───────────────────────────┼─────────────────┤
17+
│ 1 │ f1 │ 8.847e-6 │ 2.4192e-5 │
18+
│ 2 │ f2 │ 3.0109e-5 │ 7.6821e-5 │
19+
│ 3 │ f3 │ 6.1046e-6 │ 9.447e-6 │
20+
│ 4 │ f4 │ 1.6145e-5 │ 3.8827e-5 │
21+
│ 5 │ f5 │ 8.29233e-6 │ 2.2186e-5 │
22+
│ 6 │ f6 │ 3.0895e-5 │ 7.9524e-5 │
23+
│ 7 │ f7 │ 3.0847e-5 │ 7.6188e-5 │

0 commit comments

Comments
 (0)