def test(collectionSize: Int) {
println("\"Array (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 array: Array[Bar] = (1 to collectionSize).map(i =>new Bar(new Foo(i))).toArray
scalqa.Util.Benchmark(
("Array ", () => array .filter(_.foo.even).flatMap(_ => array).map(_.foo).count(_.even)),
("Array as Stream", () => array.all.filter(_.foo.even).flatMap(_ => array).map(_.foo).count(_.even)))
}
Results to Expect
"Array (size 10), test results:"
Num Name Ops/Sec % Memory % Control Value Avg
--- --------------- ------- --- ------ --- -----------------
1Array1.0m 831.2k 100252Array as Stream 1.2m 1003562825"Array (size 100), test results:"
Num Name Ops/Sec % Memory % Control Value Avg
--- --------------- ------- --- ------ --- -----------------
1Array18.6k 98101.6k 10025002Array as Stream 18.9k 1002.7k 22500"Array (size 1000), test results:"
Num Name Ops/Sec % Memory % Control Value Avg
--- --------------- ------- --- ------ --- -----------------
1Array164787.3m 1002500002Array as Stream 21010041.9k 0250000
"Array (size 10), specialized test results:"
Num Name Ops/Sec % Memory % Control Value Avg
--- --------------- ------- --- ------ --- -----------------
1Array339.9k 16001252Array as Stream 2.1m 100394100125"Array (size 100), specialized test results:"
Num Name Ops/Sec % Memory % Control Value Avg
--- --------------- ------- --- ------ --- -----------------
1Array3.8k 8152.9k 1001250002Array as Stream 45.6k 1002.1k 1125000"Array (size 1000), specialized test results:"
Num Name Ops/Sec % Memory % Control Value Avg
--- --------------- ------- --- ------ --- -----------------
1Array35716.9m 1001250000002Array as Stream 49710027.4k 0125000000
Code to Run
Results to Expect
Specialized Test
Code to Run
Results to Expect