Code to Run
def test(collectionSize: Int) { println("\"Vector (size " + collectionSize + "), test results:\"\n") import scalqa.Stream.Enable._ class Foo(val id: Int) { def even = id % 2 == 0 } class Bar(val foo: Foo) val vector: Vector[Bar] = (1 to collectionSize).map(i => new Bar(new Foo(i))).toVector scalqa.Util.Benchmark( ("Vector ", () => vector .filter(_.foo.even).flatMap(_ => vector).map(_.foo).count(_.even)), ("Vector as Stream", () => vector.all.filter(_.foo.even).flatMap(_ => vector).map(_.foo).count(_.even))) }
Results to Expect
"Vector (size 10), test results:" Num Name Ops/Sec % Memory % Control Value Avg --- ---------------- ------- --- ------ --- ----------------- 1 Vector 539.6k 33 1.9k 100 25 2 Vector as Stream 1.6m 100 386 19 25 "Vector (size 100), test results:" Num Name Ops/Sec % Memory % Control Value Avg --- ---------------- ------- --- ------ --- ----------------- 1 Vector 8.8k 42 36.6k 100 2500 2 Vector as Stream 21.0k 100 5.8k 15 2500 "Vector (size 1000), test results:" Num Name Ops/Sec % Memory % Control Value Avg --- ---------------- ------- --- ------ --- ----------------- 1 Vector 94 45 1.9m 100 250000 2 Vector as Stream 208 100 17.8k 0 250000
def specializedTest(collectionSize: Int) { println("\"Vector (size " + collectionSize + "), specialized test results:\"\n") import scalqa.Stream.Enable._ val vector: Vector[Int] = (1 to collectionSize).toVector scalqa.Util.Benchmark( ("Vector ", () => vector .filter(_ % 2 == 0).flatMap(_ => vector).map(_ / 2L).sum), ("Vector as Stream", () => vector.all.filter(_ % 2 == 0).flatMap(_ => vector).map(_ / 2L).sum)) }
"Vector (size 10), specialized test results:" Num Name Ops/Sec % Memory % Control Value Avg --- ---------------- ------- --- ------ --- ----------------- 1 Vector 412.1k 28 1.6k 100 125 2 Vector as Stream 1.4m 100 412 24 125 "Vector (size 100), specialized test results:" Num Name Ops/Sec % Memory % Control Value Avg --- ---------------- ------- --- ------ --- ----------------- 1 Vector 5.2k 23 149.4k 100 125000 2 Vector as Stream 22.0k 100 5.1k 3 125000 "Vector (size 1000), specialized test results:" Num Name Ops/Sec % Memory % Control Value Avg --- ---------------- ------- --- ------ --- ----------------- 1 Vector 47 21 7.4m 100 125000000 2 Vector as Stream 217 100 0 0 125000000
Code to Run
Results to Expect
Specialized Test
Code to Run
Results to Expect