blob: 89a27fc0650e5c6a6ffce64a544f51782b985dd6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
import scala.tools.partest._
// Attempting to verify slice isn't 100,000x slower
// with views than non-views.
class Runner(num: Int, reps: Int) extends TestUtil {
var dummy = 0
val range = Array.range(0, num)
def iteratorSlice = {
def it = range.iterator.slice(num - 2, num)
for (i <- 1 to reps)
it foreach (dummy = _)
}
def viewSlice = {
val view = range.view.slice(num - 2, num)
for (i <- 1 to reps)
view foreach (dummy = _)
}
def straightSlice = {
val xs = range.slice(num - 2, num)
for (i <- 1 to reps)
xs foreach (dummy = _)
}
def run(multiple: Double) = {
verifySpeed(straightSlice, iteratorSlice, multiple)
verifySpeed(straightSlice, viewSlice, multiple)
}
}
object Test {
def main(args: Array[String]): Unit = {
// warmup
{ val r = new Runner(1000000, 10) ; r.straightSlice ; r.iteratorSlice ; r.viewSlice }
new Runner(10000000, 10) run 100
new Runner(10000000, 50) run 50
}
}
|