-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use VB.alignTo only if RHS is significantly larger
* To cempensate for alignTo's (small, but constant) overhead, it is only called when the right Vector is mor then 64 elemente longer than the left one. * replaced some `….knownSize` by `k`
- Loading branch information
Showing
2 changed files
with
46 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...rks/src/main/scala/scala/collection/immutable/VectorConcatAlignToWorstCaseBenchmark.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package scala.collection.immutable | ||
|
||
import org.openjdk.jmh.annotations._ | ||
import org.openjdk.jmh.infra.Blackhole | ||
|
||
import java.util.concurrent.TimeUnit | ||
|
||
@BenchmarkMode(Array(Mode.AverageTime)) | ||
@Fork(1) | ||
@Threads(1) | ||
@Warmup(iterations = 4) | ||
@Measurement(iterations = 5) | ||
@OutputTimeUnit(TimeUnit.NANOSECONDS) | ||
@State(Scope.Benchmark) | ||
class VectorConcatAlignToWorstCaseBenchmark { | ||
@Param(Array("1", "15", "31", "33", "63", "65", "127", "255", "513", "1023", "1025", "2047")) // should not be divisible by 32 | ||
var size: Int = _ | ||
@Param(Array("1", "32", "64", "128", "256")) | ||
var sizeDifference: Int = _ | ||
|
||
val o = new AnyRef | ||
|
||
var shorter: Vector[String] = _ | ||
var longer: Vector[String] = _ | ||
|
||
@Setup(Level.Trial) def init(): Unit = { | ||
shorter = Vector.fill(size)("s") | ||
longer = Vector.fill(size + sizeDifference)("l") | ||
} | ||
|
||
@Benchmark def withoutAlignTo(bh: Blackhole): Any = | ||
bh.consume(new VectorBuilder[String]().addAll(shorter).addAll(longer).result()) | ||
|
||
@Benchmark def withAlignTo(bh: Blackhole): Any = | ||
bh.consume(new VectorBuilder[String]().alignTo(shorter.length, longer).addAll(shorter).addAll(longer).result()) | ||
|
||
@Benchmark def concat(bh: Blackhole): Any = | ||
bh.consume(shorter ++ longer) | ||
} |