def test(collectionSize: Int) {
println("\"List (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 list: List[Bar] = (1 to collectionSize).map(i =>new Bar(new Foo(i))).toList
scalqa.Util.Benchmark(
("List as Iterator ", () => list.toIterator.filter(_.foo.even).flatMap(_ => list).map(_.foo).count(_.even)),
("List as Stream ", () => list.all .filter(_.foo.even).flatMap(_ => list).map(_.foo).count(_.even)))
}
Results to Expect
"List (size 10), test results:"
Num Name Ops/Sec % Memory % Control Value Avg
--- ----------------- ------- --- ------ --- -----------------
1List as Iterator 1.0m 7118556252List as Stream 1.5m 10033010025"List (size 100), test results:"
Num Name Ops/Sec % Memory % Control Value Avg
--- ----------------- ------- --- ------ - -----------------
1List as Iterator 17.1k 360025002List as Stream 46.6k 100002500"List (size 1000), test results:"
Num Name Ops/Sec % Memory % Control Value Avg
--- ----------------- ------- --- ------ - -----------------
1List as Iterator 16345002500002List as Stream 35710000250000
"List (size 10), specialized test results:"
Num Name Ops/Sec % Memory % Control Value Avg
--- ---------------- ------- --- ------ --- -----------------
1List as Iterator 642.1k 57001252List as Stream 1.1m 100423100125"List (size 100), specialized test results:"
Num Name Ops/Sec % Memory % Control Value Avg
--- ---------------- ------- --- ------ --- -----------------
1List as Iterator 7.2k 26108.7k 1001250002List as Stream 27.0k 1005450125000"List (size 1000), specialized test results:"
Num Name Ops/Sec % Memory % Control Value Avg
--- ---------------- ------- --- ------ --- -----------------
1List as Iterator 6927457.7k 1001250000002List as Stream 25510010.0k 2125000000
Code to Run
Results to Expect
Specialized Test
Code to Run
Results to Expect