List Benchmark

Code to Run

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          ", () => list    .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
--- -------------- ------- --- ------ --- -----------------
1   List           545.6k  35  2.5k   100 25
2   List as Stream 1.5m    100 317    12  25

"List (size 100), test results:"

Num Name           Ops/Sec %   Memory %   Control Value Avg
--- -------------- ------- --- ------ --- -----------------
1   List           3.8k    7   224.2k 100 2500
2   List as Stream 48.8k   100 586    0   2500

"List (size 1000), test results:"

Num Name           Ops/Sec %   Memory %   Control Value Avg
--- -------------- ------- --- ------ --- -----------------
1   List           33      8   18.5m  100 250000
2   List as Stream 380     100 0      0   250000

Specialized Test

Code to Run

def specializedTest(collectionSize: Int) {
  println("\"List (size " + collectionSize + "), specialized test results:\"\n")

  import scalqa.Stream.Enable._

  val list: List[Int] = (1 to collectionSize).toList

  scalqa.Util.Benchmark(
    ("List          ", () => list    .filter(_ % 2 == 0).flatMap(_ => list).map(_ / 2L).sum),
    ("List as Stream", () => list.all.filter(_ % 2 == 0).flatMap(_ => list).map(_ / 2L).sum))
}

Results to Expect

"List (size 10), specialized test results:"

Num Name           Ops/Sec %   Memory % Control Value Av
--- -------------- ------- --- ------ - ----------------
1   List           471.7k  47  0      0 125
2   List as Stream 997.2k  100 0      0 125

"List (size 100), specialized test results:"

Num Name           Ops/Sec %   Memory %   Control Value
--- -------------- ------- --- ------ --- --------------
1   List           4.7k    17  17.5k  59  125000
2   List as Stream 27.5k   100 29.5k  100 125000

"List (size 1000), specialized test results:"

Num Name           Ops/Sec %   Memory %   Control Value
--- -------------- ------- --- ------ --- --------------
1   List           37      14  25.8m  100 125000000
2   List as Stream 253     100 36.8k  0   125000000