Skip to content

Performance concern regarding NumericRange.contains #23285

Open
@klaeufer

Description

@klaeufer

Compiler version

3.7.0 and probably all prior

Minimized example

val m = Integer.MAX_VALUE.toLong
val n = 1000000000
val i = 2L * m - 2L
val range = m until i + 1L

val t0 = System.currentTimeMillis ; (1 to n) foreach (_ => range.start <= i && i < range.end) ; System.currentTimeMillis - t0

val t1 = System.currentTimeMillis ; (1 to n) foreach (_ => range.contains(i)) ; System.currentTimeMillis - t1

Output

val i: Long = 4294967292
val m: Int = 2147483647
val n: Int = 1000000000
val range: scala.collection.immutable.NumericRange.Exclusive[Long] = NumericRange 2147483647 until 4294967293

val t0: Long = 1748538438604
val res1: Long = 5533

val t1: Long = 1748538462486
val res3: Long = 14021

Expectation

res3 should be similar to res1, not two to three times as much.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions