diff options
author | Rory Graves <rory.graves@fieldmark.co.uk> | 2016-10-17 20:25:31 +0100 |
---|---|---|
committer | Adriaan Moors <adriaan@lightbend.com> | 2017-01-28 14:02:44 -0800 |
commit | eb5c51383a63c5c3420e53ef021607ff5fd20296 (patch) | |
tree | a051a3957a2d8913346f924d943843a71ff77594 /test/benchmarks/src/main/scala | |
parent | d540bf01fe4d9e5c56a68b0d3bada9d97af77e3f (diff) | |
download | scala-eb5c51383a63c5c3420e53ef021607ff5fd20296.tar.gz scala-eb5c51383a63c5c3420e53ef021607ff5fd20296.tar.bz2 scala-eb5c51383a63c5c3420e53ef021607ff5fd20296.zip |
Optimised implementation of List.filter/filterNot
Diffstat (limited to 'test/benchmarks/src/main/scala')
-rw-r--r-- | test/benchmarks/src/main/scala/scala/collection/immutable/ListBenchmark.scala | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/test/benchmarks/src/main/scala/scala/collection/immutable/ListBenchmark.scala b/test/benchmarks/src/main/scala/scala/collection/immutable/ListBenchmark.scala new file mode 100644 index 0000000000..5ed30de7f6 --- /dev/null +++ b/test/benchmarks/src/main/scala/scala/collection/immutable/ListBenchmark.scala @@ -0,0 +1,57 @@ +package scala.collection.immutable + +import java.util.concurrent.TimeUnit + +import org.openjdk.jmh.annotations._ + +object ListBenchmark { + case class Content(value: Int) +} + +@BenchmarkMode(Array(Mode.AverageTime)) +@Fork(2) +@Threads(1) +@Warmup(iterations = 10) +@Measurement(iterations = 10) +@OutputTimeUnit(TimeUnit.NANOSECONDS) +@State(Scope.Benchmark) +class ListBenchmark { + import ListBenchmark._ + @Param(Array("0", "1", "10", "100", "1000")) + var size: Int = _ + + var values: List[Content] = _ + var mid: Content = _ + var last: Content = _ + + + @Setup(Level.Trial) def initKeys(): Unit = { + values = List.tabulate(size)(v => Content(v)) + mid = Content(size / 2) + last = Content(Math.max(0,size -1)) + } + + @Benchmark def filter_includeAll: Any = { + values.filter(v => true) + } + + @Benchmark def filter_excludeAll: Any = { + values.filter(_ => false) + } + + @Benchmark def filter_exc_mid: Any = { + values.filter(v => v.value != mid.value) + } + + @Benchmark def filter_from_mid: Any = { + values.filter(v => v.value <= mid.value) + } + + @Benchmark def filter_exc_last: Any = { + values.filter(v => v.value != last.value) + } + + @Benchmark def filter_only_last: Any = { + values.filter(v => v.value == last.value) + } +} |