|
| 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 |
0 commit comments