IntervalArithmetic.jl icon indicating copy to clipboard operation
IntervalArithmetic.jl copied to clipboard

Decorated intervals are slow

Open dpsanders opened this issue 7 years ago • 2 comments

It's expected that they're slower, but probably not this slow:

julia> using IntervalArithmetic, BenchmarkTools

julia> x = 0.1..0.2; y = 0.3..0.4;

julia> @btime $x + $y
x  6.534 ns (0 allocations: 0 bytes)
[0.399999, 0.600001]

julia> x2 = DecoratedInterval(x); y2 = DecoratedInterval(y);

julia> @btime $x2 + $y2
  16.818 ns (0 allocations: 0 bytes)
[0.399999, 0.600001]

dpsanders avatar Sep 13 '18 16:09 dpsanders

I might be completely wrong, but here is a speculation:

For bare intervals, the inner constructor Interval doesn't do any checks, those are delegated to the external function interval. I think this was motivated for efficiency reasons. For DecoratedInterval, the internal constructor does several checks, maybe this is the reason why decorated intervals are slower?

I think it might be good to have a similar "internal-without-checks" vs "external-with-checks" mechanism also for decorated intervals, at least for testing purposes.

lucaferranti avatar May 27 '21 14:05 lucaferranti

Now I get

julia> @btime $(Ref(x))[] + $(Ref(y))[]
  8.903 ns (0 allocations: 0 bytes)
[0.399999, 0.600001]

julia> @btime $(Ref(x2))[] + $(Ref(y2))[]
  13.377 ns (0 allocations: 0 bytes)
[0.399999, 0.600001]

which doesn't seem so bad.

But you're probably right, yes.

dpsanders avatar May 27 '21 14:05 dpsanders

Closing this issue since on master:

julia> @btime $(Ref(x))[] + $(Ref(y))[]
  5.875 ns (0 allocations: 0 bytes)
[0.3999999, 0.600001]

julia> @btime $(Ref(x2))[] + $(Ref(y2))[]
  8.842 ns (0 allocations: 0 bytes)
[0.3999999, 0.600001]_com

OlivierHnt avatar Aug 01 '23 09:08 OlivierHnt