Skip to content

Commit 7e89663

Browse files
rorygravesadriaanm
authored andcommitted
Add benchmark for List.mapConserve
1 parent eb5c513 commit 7e89663

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

test/benchmarks/src/main/scala/scala/collection/immutable/ListBenchmark.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,19 @@ class ListBenchmark {
5454
@Benchmark def filter_only_last: Any = {
5555
values.filter(v => v.value == last.value)
5656
}
57+
58+
@Setup(Level.Trial) def initKeys(): Unit = {
59+
values = List.tabulate(size)(n => if (n == size / 2) "mid" else "")
60+
}
61+
62+
@Benchmark def mapConserve_identity: Any = {
63+
values.mapConserve(x => x)
64+
}
65+
66+
@Benchmark def mapConserve_modifyAll: Any = {
67+
values.mapConserve(x => "replace")
68+
}
69+
@Benchmark def mapConserve_modifyMid: Any = {
70+
values.mapConserve(x => if (x == "mid") "replace" else x)
71+
}
5772
}

0 commit comments

Comments
 (0)