Good question!
f(x) = sin(exp(x));
x = range(0, 1, 800);
function test1(f, x, n)
B = ArnoldiBasis(x, n)
return B \ f
end
function test2(f, x, n)
return fit(ArnoldiFit, x, f.(x), n)
end
julia> @benchmark test1($f, $x, 16)
BenchmarkTools.Trial: 10000 samples with 1 evaluation per sample.
Range (min β¦ max): 114.875 ΞΌs β¦ 22.270 ms β GC (min β¦ max): 0.00% β¦ 99.25%
Time (median): 135.208 ΞΌs β GC (median): 0.00%
Time (mean Β± Ο): 170.619 ΞΌs Β± 366.259 ΞΌs β GC (mean Β± Ο): 20.17% Β± 12.29%
ββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
115 ΞΌs Histogram: frequency by time 1.54 ms <
Memory estimate: 631.92 KiB, allocs estimate: 53.
julia> @benchmark test2($f, $x, 16)
BenchmarkTools.Trial: 10000 samples with 1 evaluation per sample.
Range (min β¦ max): 164.667 ΞΌs β¦ 20.761 ms β GC (min β¦ max): 0.00% β¦ 98.29%
Time (median): 340.375 ΞΌs β GC (median): 0.00%
Time (mean Β± Ο): 475.733 ΞΌs Β± 604.246 ΞΌs β GC (mean Β± Ο): 30.12% Β± 22.17%
βββββββ β
βββββββββββββββββββββββββββββββ
ββββββββββββββββββββββββββββββ β
165 ΞΌs Histogram: log(frequency) by time 2.69 ms <
Memory estimate: 3.16 MiB, allocs estimate: 1360.
For evaluation, I did a separate implementation for array inputs that pays off:
y = range(0, 1, 2000)
p1 = test1(f, x, 16)
p2 = test2(f, x, 16)
julia> @benchmark $p1.($y)
BenchmarkTools.Trial: 10000 samples with 1 evaluation per sample.
Range (min β¦ max): 225.042 ΞΌs β¦ 1.282 ms β GC (min β¦ max): 0.00% β¦ 80.42%
Time (median): 236.709 ΞΌs β GC (median): 0.00%
Time (mean Β± Ο): 240.896 ΞΌs Β± 28.685 ΞΌs β GC (mean Β± Ο): 0.38% Β± 2.70%
ββ
βββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββ β
225 ΞΌs Histogram: frequency by time 288 ΞΌs <
Memory estimate: 16.06 KiB, allocs estimate: 3.
julia> @benchmark $p1($y)
BenchmarkTools.Trial: 10000 samples with 1 evaluation per sample.
Range (min β¦ max): 60.541 ΞΌs β¦ 4.412 ms β GC (min β¦ max): 0.00% β¦ 97.42%
Time (median): 74.958 ΞΌs β GC (median): 0.00%
Time (mean Β± Ο): 92.949 ΞΌs Β± 183.744 ΞΌs β GC (mean Β± Ο): 18.08% Β± 9.45%
ββ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
60.5 ΞΌs Histogram: frequency by time 907 ΞΌs <
Memory estimate: 304.14 KiB, allocs estimate: 6.
julia> p2 = test2(f, x, 16)
ArnoldiFit of degree 16
julia> @benchmark $p2.($y)
BenchmarkTools.Trial: 10000 samples with 1 evaluation per sample.
Range (min β¦ max): 174.583 ΞΌs β¦ 4.799 ms β GC (min β¦ max): 0.00% β¦ 95.91%
Time (median): 181.458 ΞΌs β GC (median): 0.00%
Time (mean Β± Ο): 246.001 ΞΌs Β± 493.594 ΞΌs β GC (mean Β± Ο): 24.63% Β± 11.59%
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ββ
β
175 ΞΌs Histogram: log(frequency) by time 4.06 ms <
Memory estimate: 391.06 KiB, allocs estimate: 4003.
Iβll have to add a mention of ArnoldiFit to the readme; I completely forgot about it. But I need the basis as well as the polynomial for some other stuff Iβm working on.