├── .gitignore
├── LICENSE
├── MavenRepository.md
├── README.md
├── build.sbt
├── core
├── build.sbt
└── src
│ ├── main
│ └── scala
│ │ └── scala
│ │ └── collection
│ │ └── immutable
│ │ └── rrbvector
│ │ ├── ParRRBVector.scala
│ │ └── RRBVector.scala
│ └── test
│ └── scala
│ └── scala
│ └── collection
│ └── immutable
│ └── rrbvector
│ ├── Issue2.scala
│ └── Issue3.scala
├── documents
├── Master Thesis - Nicolas Stucki - Turning Relaxed Radix Balanced Vector from Theory into Practice for Scala Collections (Print).pdf
├── Master Thesis - Nicolas Stucki - Turning Relaxed Radix Balanced Vector from Theory into Practice for Scala Collections.pdf
└── RRB Vector - A Practical General Purpose Immutable Sequence.pdf
├── project
├── Build.scala
└── plugins.sbt
└── src
├── main
└── scala
│ ├── codegen
│ ├── GenerateImplementations.scala
│ ├── VectorPackageGen.scala
│ ├── VectorProperties.scala
│ ├── parvector
│ │ ├── combiner
│ │ │ ├── ParVectorCombinerClassGen.scala
│ │ │ ├── ParVectorCombinerCodeGen.scala
│ │ │ └── ParVectorCombinerMethodsGen.scala
│ │ ├── iterator
│ │ │ ├── ParVectorIteratorClassGen.scala
│ │ │ ├── ParVectorIteratorCodeGen.scala
│ │ │ └── ParVectorIteratorMethodsGen.scala
│ │ ├── parvectorclass
│ │ │ ├── ParVectorClassGen.scala
│ │ │ ├── ParVectorCodeGen.scala
│ │ │ └── ParVectorMethodsGen.scala
│ │ └── parvectorobject
│ │ │ ├── ParVectorObjectClassGen.scala
│ │ │ └── ParVectorObjectMethodsGen.scala
│ ├── test
│ │ ├── VectorBenchmarksGen.scala
│ │ ├── VectorGeneratorGen.scala
│ │ └── VectorTestGen.scala
│ └── vector
│ │ ├── builder
│ │ ├── VectorBuilderClassGen.scala
│ │ ├── VectorBuilderCodeGen.scala
│ │ └── VectorBuilderMethodsGen.scala
│ │ ├── iterator
│ │ ├── VectorIteratorClassGen.scala
│ │ ├── VectorIteratorCodeGen.scala
│ │ └── VectorIteratorMethodsGen.scala
│ │ ├── reverseiterator
│ │ ├── VectorReverseIteratorClassGen.scala
│ │ ├── VectorReverseIteratorCodeGen.scala
│ │ └── VectorReverseIteratorMethodsGen.scala
│ │ ├── vectorclass
│ │ ├── VectorClassGen.scala
│ │ ├── VectorCodeGen.scala
│ │ └── VectorMethodsGen.scala
│ │ ├── vectorobject
│ │ ├── VectorObjectClassGen.scala
│ │ ├── VectorObjectCodeGen.scala
│ │ └── VectorObjectMethodsGen.scala
│ │ └── vectorpointer
│ │ ├── VectorPointerClassGen.scala
│ │ ├── VectorPointerCodeGen.scala
│ │ └── VectorPointerMethodsGen.scala
│ └── scala
│ └── collection
│ └── immutable
│ ├── cowarray
│ └── CowArray.scala
│ ├── fingertree
│ ├── FingerTree.scala
│ └── FingerTreeSeq.scala
│ ├── generated
│ └── rrbvector
│ │ ├── complete
│ │ ├── block128
│ │ │ ├── RRBVector_c_128.scala
│ │ │ └── RRBVector_c_128_asserted.scala
│ │ ├── block256
│ │ │ ├── RRBVector_c_256.scala
│ │ │ └── RRBVector_c_256_asserted.scala
│ │ ├── block32
│ │ │ ├── RRBVector_c_32.scala
│ │ │ └── RRBVector_c_32_asserted.scala
│ │ └── block64
│ │ │ ├── RRBVector_c_64.scala
│ │ │ └── RRBVector_c_64_asserted.scala
│ │ └── quick
│ │ ├── block128
│ │ ├── RRBVector_q_128.scala
│ │ └── RRBVector_q_128_asserted.scala
│ │ ├── block256
│ │ ├── RRBVector_q_256.scala
│ │ └── RRBVector_q_256_asserted.scala
│ │ ├── block32
│ │ ├── RRBVector_q_32.scala
│ │ └── RRBVector_q_32_asserted.scala
│ │ └── block64
│ │ ├── RRBVector_q_64.scala
│ │ └── RRBVector_q_64_asserted.scala
│ └── redblack
│ ├── RedBlackSeq.scala
│ └── RedBlackTree.scala
└── test
└── scala
└── scala
└── collection
└── immutable
├── vectorbenchmarks
├── BaseVectorBenchmark.scala
├── CSVReporter.scala
├── RunBenchmarks.scala
├── cowarray
│ ├── CowArrayAppendBenchmark.scala
│ ├── CowArrayApplyBenchmark.scala
│ ├── CowArrayBenchmark.scala
│ ├── CowArrayBuilderBenchmark.scala
│ ├── CowArrayConcatenationBenchmark.scala
│ ├── CowArrayIterationBenchmark.scala
│ ├── CowArrayMemoryAllocation.scala
│ ├── CowArrayPrependBenchmark.scala
│ ├── CowArraySplitBenchmark.scala
│ └── CowArrayUpdateBenchmark.scala
├── fingertree
│ ├── FingerTreeAppendBenchmark.scala
│ ├── FingerTreeApplyBenchmark.scala
│ ├── FingerTreeBenchmark.scala
│ ├── FingerTreeBuilderBenchmark.scala
│ ├── FingerTreeConcatenationBenchmark.scala
│ ├── FingerTreeIterationBenchmark.scala
│ ├── FingerTreeMemoryAllocation.scala
│ ├── FingerTreePrependBenchmark.scala
│ ├── FingerTreeSplitBenchmark.scala
│ └── FingerTreeUpdateBenchmark.scala
├── generated
│ └── rrbvector
│ │ ├── complete
│ │ ├── block128
│ │ │ └── RRBVector_c_128_Benchmark.scala
│ │ ├── block256
│ │ │ └── RRBVector_c_256_Benchmark.scala
│ │ ├── block32
│ │ │ └── RRBVector_c_32_Benchmark.scala
│ │ └── block64
│ │ │ └── RRBVector_c_64_Benchmark.scala
│ │ └── quick
│ │ ├── block128
│ │ └── RRBVector_q_128_Benchmark.scala
│ │ ├── block256
│ │ └── RRBVector_q_256_Benchmark.scala
│ │ ├── block32
│ │ └── RRBVector_q_32_Benchmark.scala
│ │ └── block64
│ │ └── RRBVector_q_64_Benchmark.scala
├── genericbenchmarks
│ ├── AppendBenchmarks.scala
│ ├── ApplyBenchmarks.scala
│ ├── BuilderBenchmarks.scala
│ ├── Concatenation2Benchmarks.scala
│ ├── ConcatenationBenchmarks.scala
│ ├── IterationBenchmarks.scala
│ ├── MemoryAllocation.scala
│ ├── ParMapBenchmarks.scala
│ ├── ParSupport.scala
│ ├── PrependBenchmarks.scala
│ ├── SplitBenchmarks.scala
│ └── UpdateBenchmarks.scala
├── redblack
│ ├── RedBlackSeqAppendBenchmark.scala
│ ├── RedBlackSeqApplyBenchmark.scala
│ ├── RedBlackSeqBenchmark.scala
│ ├── RedBlackSeqBuilderBenchmark.scala
│ ├── RedBlackSeqConcatenationBenchmark.scala
│ ├── RedBlackSeqIterationBenchmark.scala
│ ├── RedBlackSeqMemoryAllocation.scala
│ ├── RedBlackSeqPrependBenchmark.scala
│ ├── RedBlackSeqSplitBenchmark.scala
│ └── RedBlackSeqUpdateBenchmark.scala
├── rrbvector
│ ├── balanced
│ │ ├── RRBVectorAbstractBenchmark.scala
│ │ ├── RRBVectorAbstractPrependBenchmark.scala
│ │ ├── RRBVectorAppendBenchmark.scala
│ │ ├── RRBVectorApplyBenchmark.scala
│ │ ├── RRBVectorBuilderBenchmark.scala
│ │ ├── RRBVectorConcatenationBenchmark.scala
│ │ ├── RRBVectorIterationBenchmark.scala
│ │ ├── RRBVectorMemoryAllocation.scala
│ │ ├── RRBVectorParMapBenchmark.scala
│ │ ├── RRBVectorSplitBenchmark.scala
│ │ └── RRBVectorUpdateBenchmark.scala
│ ├── unbalanced1
│ │ ├── RRBVectorAbstractBenchmark.scala
│ │ ├── RRBVectorAbstractPrependBenchmark.scala
│ │ ├── RRBVectorAppendBenchmark.scala
│ │ ├── RRBVectorApplyBenchmark.scala
│ │ ├── RRBVectorBuilderBenchmark.scala
│ │ ├── RRBVectorConcatenationBenchmark.scala
│ │ ├── RRBVectorIterationBenchmark.scala
│ │ ├── RRBVectorMemoryAllocation.scala
│ │ ├── RRBVectorParMapBenchmark.scala
│ │ ├── RRBVectorSplitBenchmark.scala
│ │ └── RRBVectorUpdateBenchmark.scala
│ └── xunbalanced
│ │ ├── RRBVectorAbstractBenchmark.scala
│ │ ├── RRBVectorAbstractPrependBenchmark.scala
│ │ ├── RRBVectorAppendBenchmark.scala
│ │ ├── RRBVectorApplyBenchmark.scala
│ │ ├── RRBVectorBuilderBenchmark.scala
│ │ ├── RRBVectorConcatenationBenchmark.scala
│ │ ├── RRBVectorIterationBenchmark.scala
│ │ ├── RRBVectorMemoryAllocation.scala
│ │ ├── RRBVectorParMapBenchmark.scala
│ │ ├── RRBVectorSplitBenchmark.scala
│ │ └── RRBVectorUpdateBenchmark.scala
└── vector
│ ├── VectorAppendBenchmark.scala
│ ├── VectorApplyBenchmark.scala
│ ├── VectorBenchmark.scala
│ ├── VectorBuilderBenchmark.scala
│ ├── VectorConcatenationBenchmark.scala
│ ├── VectorIterationBenchmark.scala
│ ├── VectorMemoryAllocation.scala
│ ├── VectorParMapBenchmark.scala
│ ├── VectorPrependBenchmark.scala
│ ├── VectorSplitBenchmark.scala
│ └── VectorUpdateBenchmark.scala
├── vectortests
├── QuickTest.scala
├── VectorSpec.scala
├── cowarray
│ └── CowArrayTest.scala
├── fingertree
│ └── FingerTreeSeqTest.scala
├── generated
│ └── rrbvector
│ │ ├── complete
│ │ ├── block128
│ │ │ ├── RRBVectorTest_c_128.scala
│ │ │ └── RRBVectorTest_c_128_asserted.scala
│ │ ├── block256
│ │ │ ├── RRBVectorTest_c_256.scala
│ │ │ └── RRBVectorTest_c_256_asserted.scala
│ │ ├── block32
│ │ │ ├── RRBVectorTest_c_32.scala
│ │ │ └── RRBVectorTest_c_32_asserted.scala
│ │ └── block64
│ │ │ ├── RRBVectorTest_c_64.scala
│ │ │ └── RRBVectorTest_c_64_asserted.scala
│ │ └── quick
│ │ ├── block128
│ │ ├── RRBVectorTest_q_128.scala
│ │ └── RRBVectorTest_q_128_asserted.scala
│ │ ├── block256
│ │ ├── RRBVectorTest_q_256.scala
│ │ └── RRBVectorTest_q_256_asserted.scala
│ │ ├── block32
│ │ ├── RRBVectorTest_q_32.scala
│ │ └── RRBVectorTest_q_32_asserted.scala
│ │ └── block64
│ │ ├── RRBVectorTest_q_64.scala
│ │ └── RRBVectorTest_q_64_asserted.scala
├── redblack
│ └── RedBlackTest.scala
├── rrbvector
│ └── RRBVectorTest.scala
└── vector
│ └── VectorTest.scala
└── vectorutils
├── VectorGenerator.scala
├── VectorGeneratorType.scala
├── VectorOps.scala
└── generated
└── rrbvector
├── complete
├── block128
│ ├── RRBVectorGenerator_c_128.scala
│ └── RRBVectorGenerator_c_128_asserted.scala
├── block256
│ ├── RRBVectorGenerator_c_256.scala
│ └── RRBVectorGenerator_c_256_asserted.scala
├── block32
│ ├── RRBVectorGenerator_c_32.scala
│ └── RRBVectorGenerator_c_32_asserted.scala
└── block64
│ ├── RRBVectorGenerator_c_64.scala
│ └── RRBVectorGenerator_c_64_asserted.scala
└── quick
├── block128
├── RRBVectorGenerator_q_128.scala
└── RRBVectorGenerator_q_128_asserted.scala
├── block256
├── RRBVectorGenerator_q_256.scala
└── RRBVectorGenerator_q_256_asserted.scala
├── block32
├── RRBVectorGenerator_q_32.scala
└── RRBVectorGenerator_q_32_asserted.scala
└── block64
├── RRBVectorGenerator_q_64.scala
└── RRBVectorGenerator_q_64_asserted.scala
/.gitignore:
--------------------------------------------------------------------------------
1 | # Eclipse
2 | .classpath
3 | .project
4 | .settings/
5 |
6 | # Intellij
7 | .idea/
8 | *.iml
9 | *.iws
10 |
11 | # Mac
12 | .DS_Store
13 |
14 | # Maven
15 | log/
16 | target/
17 |
18 | # Scalameter
19 | tmp/*
20 | benchmarks_outputs/*
--------------------------------------------------------------------------------
/MavenRepository.md:
--------------------------------------------------------------------------------
1 | Maven repository
2 | ================
3 |
4 | The last version of Scala RRB Vector is 0.1.1
5 |
6 | Scala multisets can be downloaded from Maven Central.
7 | ```xml
8 |
9 | io.github.nicolasstucki
10 | scala-rrb-vector
11 | 0.1.1
12 |
13 | ```
14 |
15 |
16 | To use it with SBT, just add the following dependency to `build.sbt`:
17 | ```scala
18 | libraryDependencies ++= Seq("io.github.nicolasstucki" %% "scala-rrb-vector" % "0.1.1")
19 | ```
20 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | This projects aims to implement and benchmark Scala `immutable.Vector` using [Relaxed-Radix-Balanced Trees](https://github.com/TiarkRompf/rrbtrees) without loosing the current performance and low level oprimizations on cummon Radix-Ballanced Trees (i.e. Scala `immutable.Vector`).
3 |
4 | Documentation
5 | --------------------
6 | * [ICFP 2015 Paper](https://github.com/nicolasstucki/scala-rrb-vector/blob/master/documents/RRB%20Vector%20-%20A%20Practical%20General%20Purpose%20Immutable%20Sequence.pdf)
7 | * [ICFP 2015 Slides](https://docs.google.com/presentation/d/1vEhfNgV0eVtvWDkkh88MSIpWP7FSgFgSxa4SbVdO0Q8/edit?usp=sharing
8 | Maven repository)
9 | * [Thesis Paper](https://github.com/nicolasstucki/scala-rrb-vector/blob/master/documents/Master%20Thesis%20-%20Nicolas%20Stucki%20-%20Turning%20Relaxed%20Radix%20Balanced%20Vector%20from%20Theory%20into%20Practice%20for%20Scala%20Collections.pdf?raw=true) ([printable version](https://github.com/nicolasstucki/scala-rrb-vector/blob/master/documents/Master%20Thesis%20-%20Nicolas%20Stucki%20-%20Turning%20Relaxed%20Radix%20Balanced%20Vector%20from%20Theory%20into%20Practice%20for%20Scala%20Collections%20(Print).pdf?raw=true))
10 | * [Thesis Slides](https://docs.google.com/presentation/d/1GY0p2P-BzPfWspKoMRxOQ87fG01t4oMJ1PJxjxGFurQ/edit?usp=sharing)
11 |
12 | Maven repository
13 | -----------------------
14 | It is availabe on [Maven Central](https://github.com/nicolasstucki/scala-rrb-vector/blob/master/MavenRepository.md)
15 |
--------------------------------------------------------------------------------
/build.sbt:
--------------------------------------------------------------------------------
1 | name := "scala-rrb-vector"
2 |
3 | version := "0.1"
4 |
5 | scalaVersion := "2.11.2"
6 |
7 | resolvers += "Sonatype OSS Snapshots" at
8 | "https://oss.sonatype.org/content/repositories/releases"
9 |
10 | libraryDependencies ++= Seq(
11 | "org.scalatest" % "scalatest_2.11" % "2.2.1" % "test",
12 | "com.storm-enroute" %% "scalameter" % "0.6"
13 | )
14 |
15 | testFrameworks += new TestFramework("org.scalameter.ScalaMeterFramework")
16 |
17 | parallelExecution in Test := false
18 |
--------------------------------------------------------------------------------
/core/build.sbt:
--------------------------------------------------------------------------------
1 | name := "scala-rrb-vector"
2 |
3 | version := "0.1.1-SNAPSHOT"
4 |
5 | scalaVersion := "2.11.6"
6 |
7 | resolvers += "Sonatype OSS Snapshots" at
8 | "https://oss.sonatype.org/content/repositories/releases"
9 |
10 | organization := "io.github.nicolasstucki"
11 |
12 | publishTo := {
13 | val nexus = "https://oss.sonatype.org/"
14 | if (isSnapshot.value)
15 | Some("snapshots" at nexus + "content/repositories/snapshots")
16 | else
17 | Some("releases" at nexus + "service/local/staging/deploy/maven2")
18 | }
19 |
20 | libraryDependencies += "org.scalatest" % "scalatest_2.11" % "2.2.4" % "test"
21 |
22 | publishMavenStyle := true
23 |
24 | publishArtifact in Test := false
25 |
26 | pomIncludeRepository := { _ => false }
27 |
28 | pomExtra := (
29 | https://github.com/nicolasstucki/scala-rrb-vector
30 |
31 |
32 | BSD-style
33 | http://www.opensource.org/licenses/bsd-license.php
34 | repo
35 |
36 |
37 |
38 | git@github.com:nicolasstucki/scala-rrb-vector.git
39 | scm:git:git@github.com:nicolasstucki/scala-rrb-vector.git
40 |
41 |
42 |
43 | nicolas.stucki
44 | Nicolas Stucki
45 | http://io.github.nicolasstucki
46 |
47 |
48 | )
49 |
--------------------------------------------------------------------------------
/core/src/test/scala/scala/collection/immutable/rrbvector/Issue2.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.rrbvector
2 |
3 | import org.scalatest._
4 |
5 | class Issue2 extends FlatSpec with Matchers {
6 | "Code in issue #2" should "not throw a NPE" in {
7 | import scala.util.Random
8 |
9 | object Mutate {
10 | def apply(rnd : Random, xs : IndexedSeq[Boolean] ): IndexedSeq[Boolean] = {
11 | val point = rnd.nextInt(xs.length)
12 | xs.updated(point, !xs(point))
13 | }
14 |
15 | def apply2(rnd : Random, xs : IndexedSeq[Boolean] ): IndexedSeq[Boolean] = {
16 | val point = rnd.nextInt(xs.length)
17 | val (ys,zs) = xs.splitAt(point)
18 | ys ++ (!zs.head +: zs.tail)
19 | }
20 | }
21 |
22 | val iterations = 100000
23 | val top_length = 4096
24 | val repeats = 1
25 |
26 | def test(descr : String, init : (Random,Int) => IndexedSeq[Boolean]) {
27 | var len = 16
28 | val rnd = new Random(0)
29 | do {
30 | val indi = init(rnd,len)
31 |
32 | var times = 0.0
33 | for(i <- 0 until repeats) {
34 | val initialTime = System.nanoTime()
35 | for (i <- 1 until iterations) {
36 | val newIndi = Mutate.apply2(rnd,indi)
37 | }
38 | val finalTime = System.nanoTime()
39 | times += finalTime - initialTime
40 | }
41 | val avg = times/repeats
42 | println( descr+", "+len+", "+avg/1e9 )
43 | len = len * 2
44 | } while ( len <= top_length )
45 | }
46 |
47 | test("Scala-Vector[Boolean]", (rnd, len) => Vector.fill(len)(rnd.nextDouble > 0.5))
48 |
49 | test("Scala-RRBVector[Boolean]", (rnd,len) => RRBVector.fill(len)(rnd.nextDouble > 0.5))
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/core/src/test/scala/scala/collection/immutable/rrbvector/Issue3.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.rrbvector
2 |
3 | import org.scalatest._
4 |
5 | class Issue3 extends FlatSpec with Matchers {
6 | "Code in issue #3" should "not throw" in {
7 | RRBVector.fill(/*32^5 + 1*/ 33554433)(0).apply(1024) // NPE
8 | RRBVector.fill(/*32^5 + 1*/33554433)(0).foreach(_ => ())
9 | }
10 |
11 | "Code in issue #3" should " should be correctly filled" in {
12 | val vector = RRBVector.fill(/*32^5 + 1*/ 33554433)(0)
13 | for (i <- 0 until 33554433)
14 | assert(vector(i) == 0, "failed at index " + i)
15 | println()
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/documents/Master Thesis - Nicolas Stucki - Turning Relaxed Radix Balanced Vector from Theory into Practice for Scala Collections (Print).pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nicolasstucki/scala-rrb-vector/cd6dcc04e8ba4e495a3691efe55445bbdad50278/documents/Master Thesis - Nicolas Stucki - Turning Relaxed Radix Balanced Vector from Theory into Practice for Scala Collections (Print).pdf
--------------------------------------------------------------------------------
/documents/Master Thesis - Nicolas Stucki - Turning Relaxed Radix Balanced Vector from Theory into Practice for Scala Collections.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nicolasstucki/scala-rrb-vector/cd6dcc04e8ba4e495a3691efe55445bbdad50278/documents/Master Thesis - Nicolas Stucki - Turning Relaxed Radix Balanced Vector from Theory into Practice for Scala Collections.pdf
--------------------------------------------------------------------------------
/documents/RRB Vector - A Practical General Purpose Immutable Sequence.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nicolasstucki/scala-rrb-vector/cd6dcc04e8ba4e495a3691efe55445bbdad50278/documents/RRB Vector - A Practical General Purpose Immutable Sequence.pdf
--------------------------------------------------------------------------------
/project/Build.scala:
--------------------------------------------------------------------------------
1 | import sbt._
2 | import Keys._
3 |
4 | object RRBVectorBuild extends Build {
5 |
6 | lazy val root = Project(id = "scala-rrb-vector",
7 | base = file(".")) dependsOn(coreRRBVector % "test->compile") aggregate(coreRRBVector)
8 |
9 |
10 | lazy val coreRRBVector = Project(id = "scala-rrb-vector-core",
11 | base = file("core"))
12 |
13 | }
--------------------------------------------------------------------------------
/project/plugins.sbt:
--------------------------------------------------------------------------------
1 | logLevel := Level.Warn
--------------------------------------------------------------------------------
/src/main/scala/codegen/GenerateImplementations.scala:
--------------------------------------------------------------------------------
1 | package codegen
2 |
3 | import vector.builder._
4 | import vector.vectorclass._
5 | import vector.iterator._
6 | import vector.vectorobject._
7 | import vector.vectorpointer._
8 | import vector.reverseiterator._
9 |
10 | import parvector.parvectorclass._
11 | import parvector.parvectorobject._
12 | import parvector.iterator._
13 | import parvector.combiner._
14 |
15 | import test._
16 |
17 | import scala.reflect.runtime.universe._
18 |
19 | object GenerateImplementations extends App {
20 |
21 | def saveToFile(path: String, code: String) = {
22 | new java.io.File(path).getParentFile.mkdirs()
23 | val writer = new java.io.PrintWriter(path)
24 | try {
25 | writer.write(code)
26 | println("Exported to: " + path)
27 | }
28 | finally writer.close()
29 | }
30 |
31 | abstract class VectorImplementation
32 | extends VectorPackageGen with VectorProperties
33 | with VectorObjectClassGen with VectorObjectMethodsGen with VectorObjectCodeGen
34 | with VectorClassGen with VectorMethodsGen with VectorCodeGen
35 | with VectorBuilderClassGen with VectorBuilderMethodsGen with VectorBuilderCodeGen
36 | with VectorIteratorClassGen with VectorIteratorMethodsGen with VectorIteratorCodeGen
37 | with VectorReverseIteratorClassGen with VectorReverseIteratorMethodsGen with VectorReverseIteratorCodeGen
38 | with VectorPointerClassGen with VectorPointerMethodsGen with VectorPointerCodeGen
39 | with ParVectorClassGen with ParVectorMethodsGen with ParVectorCodeGen
40 | with ParVectorObjectClassGen with ParVectorObjectMethodsGen
41 | with ParVectorIteratorClassGen with ParVectorIteratorMethodsGen with ParVectorIteratorCodeGen
42 | with ParVectorCombinerClassGen with ParVectorCombinerMethodsGen with ParVectorCombinerCodeGen
43 |
44 | with VectorGeneratorGen with VectorTestGen with VectorBenchmarksGen {
45 |
46 | def outputFile = {
47 | val subpackagePath = subpackage.toString.replace('.', '/')
48 | s"./src/main/scala/scala/collection/immutable/generated/$subpackagePath/${vectorName()}.scala"
49 | }
50 |
51 | def outputGeneratorFile = {
52 | val subpackagePath = subpackage.toString.replace('.', '/')
53 | s"./src/test/scala/scala/collection/immutable/vectorutils/generated/$subpackagePath/$vectorGeneratorClassName.scala"
54 | }
55 |
56 | def outputTestFile = {
57 | val subpackagePath = subpackage.toString.replace('.', '/')
58 | s"./src/test/scala/scala/collection/immutable/vectortests/generated/$subpackagePath/$vectorTestClassName.scala"
59 | }
60 |
61 | def outputBenchmarkFile = {
62 | val subpackagePath = subpackage.toString.replace('.', '/')
63 | s"./src/test/scala/scala/collection/immutable/vectorbenchmarks/generated/$subpackagePath/$vectorBaseBenchmarkClassName.scala"
64 | }
65 |
66 | def exportCodeToFiles() = {
67 | saveToFile(outputFile, showCode(generateVectorPackage()) + "\n\n" + showCode(generateParVectorPackage()))
68 | saveToFile(outputGeneratorFile, showCode(generateVectorGeneratorClass()))
69 | saveToFile(outputTestFile, showCode(generateVectorTestClasses()))
70 | if (!useAssertions) {
71 | saveToFile(outputBenchmarkFile, showCode(generateVectorBenchmarkClasses()))
72 | }
73 | }
74 | }
75 |
76 | val USE_ASSERTIONS = false
77 |
78 | for {
79 | completeRebalanceOn <- Iterator(true, false)
80 | assertionsOn <- Iterator(true, false)
81 | indexBits <- 5 to 8
82 | } {
83 | val packageGenerator = new VectorImplementation {
84 | protected val useCompleteRebalance: Boolean = completeRebalanceOn
85 | protected val useAssertions: Boolean = assertionsOn
86 | override protected val blockIndexBits: Int = indexBits
87 | }
88 | packageGenerator.exportCodeToFiles()
89 | }
90 |
91 | }
--------------------------------------------------------------------------------
/src/main/scala/codegen/VectorPackageGen.scala:
--------------------------------------------------------------------------------
1 | package codegen
2 |
3 | import codegen.parvector.combiner.ParVectorCombinerClassGen
4 | import codegen.parvector.iterator.ParVectorIteratorClassGen
5 | import codegen.parvector.parvectorclass.ParVectorClassGen
6 | import codegen.parvector.parvectorobject.ParVectorObjectClassGen
7 | import vector.builder.VectorBuilderClassGen
8 | import vector.iterator.VectorIteratorClassGen
9 | import vector.vectorobject.VectorObjectClassGen
10 | import vector.vectorclass.VectorClassGen
11 | import vector.vectorpointer.VectorPointerClassGen
12 | import vector.reverseiterator.VectorReverseIteratorClassGen
13 |
14 | import scala.reflect.runtime.universe._
15 |
16 | trait VectorPackageGen {
17 | self: VectorProperties
18 | with VectorObjectClassGen
19 | with VectorClassGen
20 | with VectorBuilderClassGen
21 | with VectorIteratorClassGen
22 | with VectorReverseIteratorClassGen
23 | with VectorPointerClassGen
24 | with ParVectorClassGen
25 | with ParVectorObjectClassGen
26 | with ParVectorIteratorClassGen
27 | with ParVectorCombinerClassGen =>
28 |
29 | def generateVectorPackage() = {
30 | inPackages(s"scala.collection.immutable.generated".split('.'),
31 | q"""
32 | package $subpackage {
33 | import scala.annotation.tailrec
34 | import scala.compat.Platform
35 | import scala.annotation.unchecked.uncheckedVariance
36 | import scala.collection.generic.{GenericCompanion, GenericTraversableTemplate, CanBuildFrom, IndexedSeqFactory}
37 | import scala.collection.parallel.immutable.generated.$subpackage.$parVectorClassName
38 | ..${generateClassesDef()}
39 | }
40 | """)
41 | }
42 |
43 | def generateParVectorPackage() = {
44 | inPackages(s"scala.collection.parallel.immutable.generated".split('.'),
45 | q"""
46 | package $subpackage {
47 | import scala.collection.immutable.generated.$subpackage._
48 | import scala.collection.generic.{GenericParTemplate, CanCombineFrom, ParFactory}
49 | import scala.collection.parallel.{ParSeqLike, Combiner, SeqSplitter}
50 | import scala.collection.mutable.ArrayBuffer
51 |
52 | ..${generateParClassesDef()}
53 | }
54 | """)
55 | }
56 |
57 | def generateClassesDef(): Seq[Tree] = {
58 | generateVectorObjectClassDef() :: generateVectorClassDef() :: generateVectorBuilderClassDef() ::
59 | generateVectorIteratorClassDef() :: generateVectorReverseIteratorClassDef() :: generateVectorPointerClassDef() :: Nil
60 | }
61 |
62 | def generateParClassesDef(): Seq[Tree] = {
63 | generateParVectorClassDef() :: generateParVectorObjectDef() :: generateParVectorCombinerClassDef() :: Nil
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/main/scala/codegen/VectorProperties.scala:
--------------------------------------------------------------------------------
1 | package codegen
2 |
3 | import scala.reflect.runtime.universe._
4 |
5 | trait VectorProperties {
6 |
7 | protected val useCompleteRebalance: Boolean
8 |
9 | protected val useAssertions: Boolean
10 |
11 | protected val blockIndexBits: Int
12 |
13 |
14 | protected final def blockWidth = 1 << blockIndexBits
15 |
16 | protected final def blockMask = blockWidth - 1
17 |
18 | protected final def maxTreeLevel = 31 / blockIndexBits /* 31 for bits that are used to represent positive Int for indices*/
19 |
20 | protected final def maxTreeDepth = maxTreeLevel + 1
21 |
22 | protected final val blockInvariants = 1
23 |
24 | protected final val A = TypeName("A")
25 |
26 | protected final val B = TypeName("B")
27 |
28 |
29 | protected def vectorObjectName = TermName(vectorName())
30 |
31 | protected def vectorClassName = TypeName(vectorName())
32 |
33 | protected def vectorPointerClassName = TypeName(vectorName("Pointer"))
34 |
35 | protected def vectorBuilderClassName = TypeName(vectorName("Builder"))
36 |
37 | protected def vectorIteratorClassName = TypeName(vectorName("Iterator"))
38 |
39 | protected def vectorReverseIteratorClassName = TypeName(vectorName("ReverseIterator"))
40 |
41 | protected def vectorGeneratorClassName = TypeName(vectorName("Generator"))
42 |
43 |
44 | protected def parVectorClassName = TypeName("Par" + vectorName())
45 |
46 | protected def parVectorObjectTypeName = TypeName("Par" + vectorName())
47 |
48 | protected def parVectorObjectTermName = TermName("Par" + vectorName())
49 |
50 | protected def parVectorIteratorClassName = TypeName("Par" + vectorName("Iterator"))
51 |
52 | protected def parVectorCombinerClassName = TypeName("Par" + vectorName("Combinator"))
53 |
54 |
55 | protected def vectorTestClassName = TypeName(vectorName("Test"))
56 |
57 | protected def vectorBaseBenchmarkClassName = vectorBenchmarkClassName("")
58 |
59 | protected def vectorBenchmarkClassName(method: String) = TypeName(vectorName() + "_" + (if (method != "") method + "_" else "") + "Benchmark")
60 |
61 | def subpackage: TermName = {
62 | val balanceType = if (useCompleteRebalance) "complete" else "quick"
63 |
64 | TermName(s"rrbvector.$balanceType.block$blockWidth")
65 | }
66 |
67 | def vectorName(namePostfix: String = ""): String = {
68 | val balanceType = if (useCompleteRebalance) "_c" else "_q"
69 | val assertedStr = if (useAssertions) "_asserted" else ""
70 | val blockWidthStr = "_" + blockWidth
71 | s"RRBVector$namePostfix$balanceType$blockWidthStr$assertedStr"
72 | }
73 |
74 | protected def inPackages(packages: Seq[String], code: Tree): Tree = {
75 | if (packages.nonEmpty) {
76 | val packageName = TermName(packages.head)
77 | q"package $packageName { ${inPackages(packages.tail, code)} }"
78 | } else code
79 | }
80 |
81 | protected def assertions(asserts: Tree*): Seq[Tree] = {
82 | if (useAssertions) asserts map (a => q"assert($a)")
83 | else Nil
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/src/main/scala/codegen/parvector/combiner/ParVectorCombinerClassGen.scala:
--------------------------------------------------------------------------------
1 | package codegen
2 | package parvector
3 | package combiner
4 |
5 | import scala.reflect.runtime.universe._
6 |
7 | trait ParVectorCombinerClassGen {
8 | self: ParVectorCombinerMethodsGen with VectorProperties with ParVectorCombinerCodeGen =>
9 |
10 | def generateParVectorCombinerClassDef(): Tree = {
11 | q"""
12 | private[immutable] class $parVectorCombinerClassName[$A] extends Combiner[$A, $parVectorClassName[$A]] {
13 | ..${generateParVectorCombinerMethods()}
14 | }
15 | """
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/scala/codegen/parvector/combiner/ParVectorCombinerCodeGen.scala:
--------------------------------------------------------------------------------
1 | package codegen
2 | package parvector
3 | package combiner
4 |
5 | import iterator.ParVectorIteratorClassGen
6 | import vector.vectorpointer.VectorPointerCodeGen
7 |
8 | import scala.reflect.runtime.universe._
9 |
10 | trait ParVectorCombinerCodeGen {
11 | self: VectorProperties with VectorPointerCodeGen with ParVectorIteratorClassGen =>
12 |
13 | // Field names
14 |
15 | val comb_builder = TermName("builder")
16 |
17 | // Method definitions
18 |
19 | protected def plusEqCode(elem: TermName) = {
20 | q"""
21 | $comb_builder += $elem
22 | this
23 | """
24 | }
25 |
26 | protected def plusPlusCode(xs: TermName) = {
27 | q"""
28 | $comb_builder ++= $xs
29 | this
30 | """
31 | }
32 |
33 | protected def combineCode(other: TermName) = {
34 | // q"""
35 | // if ($other eq this) this
36 | // else {
37 | // val that = $other.asInstanceOf[$parVectorCombinerClassName[$B]]
38 | // $comb_builder ++= that.$comb_builder.result()
39 | // this
40 | // }
41 | // """
42 | q"""
43 | if ($other eq this) this
44 | else {
45 | val newCombiner = new $parVectorCombinerClassName[$A]
46 | newCombiner ++= this.builder.result()
47 | newCombiner ++= $other.asInstanceOf[$parVectorCombinerClassName[$A]].builder.result()
48 | newCombiner
49 | }
50 | """
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/scala/codegen/parvector/combiner/ParVectorCombinerMethodsGen.scala:
--------------------------------------------------------------------------------
1 | package codegen
2 | package parvector
3 | package combiner
4 |
5 | import codegen.vector.vectorpointer.VectorPointerCodeGen
6 |
7 | import scala.reflect.runtime.universe._
8 |
9 | trait ParVectorCombinerMethodsGen {
10 | self: ParVectorCombinerCodeGen with VectorPointerCodeGen with VectorProperties =>
11 |
12 | def generateParVectorCombinerMethods() = {
13 | val fields = Seq(
14 | q"val builder: $vectorBuilderClassName[$A] = new $vectorBuilderClassName[$A]"
15 | )
16 | val methods = Seq(
17 | sizeDef,
18 | resultDef,
19 | clearDef,
20 | plusEqDef,
21 | plusPlusDef,
22 | combineDef)
23 |
24 | fields ++ methods
25 | }
26 |
27 | private def sizeDef =
28 | q"override def size = $comb_builder.$endIndex"
29 |
30 | private def resultDef =
31 | q"override def result() = new $parVectorClassName[$A]($comb_builder.result())"
32 |
33 | private def clearDef =
34 | q"override def clear() = $comb_builder.clear()"
35 |
36 | private def plusEqDef = {
37 | val elem = TermName("elem")
38 | val code = plusEqCode(elem)
39 | q"override def +=($elem: $A) = $code"
40 | }
41 |
42 | private def plusPlusDef = {
43 | val xs = TermName("xs")
44 | val code = plusPlusCode(xs)
45 | q"override def ++=($xs: TraversableOnce[$A]) = $code"
46 | }
47 |
48 | private def combineDef = {
49 | val other = TermName("other")
50 | val code = combineCode(other)
51 | q"def combine[$B <: $A, NewTo >: $parVectorClassName[$A]]($other: Combiner[$B, NewTo]) = $code"
52 | }
53 | }
54 |
55 |
--------------------------------------------------------------------------------
/src/main/scala/codegen/parvector/iterator/ParVectorIteratorClassGen.scala:
--------------------------------------------------------------------------------
1 | package codegen
2 | package parvector
3 | package iterator
4 |
5 |
6 | import scala.reflect.runtime.universe._
7 |
8 | trait ParVectorIteratorClassGen {
9 | self: ParVectorIteratorMethodsGen with VectorProperties with ParVectorIteratorCodeGen =>
10 |
11 | def generateParVectorIteratorClassDef(): Tree = {
12 | q"""
13 | class $parVectorIteratorClassName($pit_start: Int, $pit_end: Int) extends $vectorIteratorClassName[$A]($pit_start, $pit_end) with SeqSplitter[$A] {
14 | ..${generateParVectorIteratorMethods()}
15 | }
16 | """
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/scala/codegen/parvector/iterator/ParVectorIteratorCodeGen.scala:
--------------------------------------------------------------------------------
1 | package codegen.parvector.iterator
2 |
3 | import codegen.VectorProperties
4 | import codegen.vector.iterator.VectorIteratorCodeGen
5 | import codegen.vector.vectorpointer.VectorPointerCodeGen
6 |
7 | import scala.reflect.runtime.universe._
8 |
9 | trait ParVectorIteratorCodeGen {
10 | self: VectorProperties with VectorIteratorCodeGen with VectorPointerCodeGen =>
11 |
12 | // Field names
13 |
14 | val pit_start = TermName("_start")
15 | val pit_end = TermName("_end")
16 |
17 | val pit_remaining = TermName("remaining")
18 | val pit_dup = TermName("dup")
19 | val pit_split = TermName("split")
20 | val pit_psplit = TermName("psplit")
21 |
22 | // Method definitions
23 |
24 | protected def dupCode() = {
25 | q"""
26 | val pit = new $parVectorIteratorClassName($pit_end - $pit_remaining, $pit_end)
27 | pit.$it_initIteratorFrom(this)
28 | pit
29 | """
30 | }
31 |
32 | protected def splitCode(): Tree = {
33 | def splitModulo(lvl: Int): Tree = {
34 | q"""
35 | if (rem <= ${1 << (blockIndexBits * lvl)}) ${1 << (blockIndexBits * (lvl - 1))}
36 | else ${if (lvl < maxTreeLevel) splitModulo(lvl + 1) else q"${1 << (blockIndexBits * lvl)}"}
37 | """
38 | }
39 | q"""
40 | val rem = $pit_remaining
41 | if (rem >= 2) {
42 | val _half = rem / 2
43 | val _splitModulo = ${splitModulo(1)}
44 | val _halfAdjusted = if (_half > _splitModulo) _half - _half % _splitModulo else if (_splitModulo < _end) _splitModulo else _half
45 | psplit(_halfAdjusted, rem - _halfAdjusted)
46 | }
47 | else Seq(this)
48 | """
49 | }
50 |
51 |
52 | protected def splitterCode(sizes: TermName) = {
53 | q"""
54 | val splitted = new ArrayBuffer[$parVectorIteratorClassName]
55 | var currentPos = $pit_end - $pit_remaining
56 | for (sz <- $sizes) {
57 | val pit = new $parVectorIteratorClassName(currentPos, currentPos + sz)
58 | pit.$it_initIteratorFrom(this)
59 | splitted += pit
60 | currentPos += sz
61 | }
62 | splitted
63 | """
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/src/main/scala/codegen/parvector/iterator/ParVectorIteratorMethodsGen.scala:
--------------------------------------------------------------------------------
1 | package codegen
2 | package parvector
3 | package iterator
4 |
5 | import vector.iterator.VectorIteratorCodeGen
6 |
7 | import codegen.VectorProperties
8 |
9 | import scala.reflect.runtime.universe._
10 |
11 | trait ParVectorIteratorMethodsGen {
12 | self: ParVectorIteratorCodeGen with VectorProperties with VectorIteratorCodeGen =>
13 |
14 | def generateParVectorIteratorMethods() = {
15 | val methods = Seq(
16 | remainingDef,
17 | dupDef,
18 | splitDef,
19 | psplitDef)
20 | methods
21 | }
22 |
23 |
24 | private def remainingDef =
25 | q"override final def $it_remaining: Int = super.$it_remaining"
26 |
27 | private def dupDef = {
28 | val code = dupCode()
29 | q"def $pit_dup: SeqSplitter[$A] = $code"
30 | }
31 |
32 | private def splitDef = {
33 | val code = splitCode()
34 | q"def $pit_split: Seq[$parVectorIteratorClassName] = $code"
35 | }
36 |
37 | private def psplitDef = {
38 | val sizes = TermName("sizes")
39 | val code = splitterCode(sizes)
40 | q"def $pit_psplit($sizes: Int*): Seq[$parVectorIteratorClassName] = $code"
41 | }
42 |
43 | }
44 |
45 |
--------------------------------------------------------------------------------
/src/main/scala/codegen/parvector/parvectorclass/ParVectorClassGen.scala:
--------------------------------------------------------------------------------
1 | package codegen
2 | package parvector
3 | package parvectorclass
4 |
5 |
6 | import scala.reflect.runtime.universe._
7 |
8 | trait ParVectorClassGen {
9 | self: ParVectorMethodsGen with VectorProperties with ParVectorCodeGen =>
10 |
11 | def generateParVectorClassDef(): Tree = {
12 | q"""
13 | class $parVectorClassName[+$A](private[this] val $par_vector: $vectorClassName[$A])
14 | extends ParSeq[$A]
15 | with GenericParTemplate[$A, $parVectorObjectTypeName]
16 | with ParSeqLike[$A, $parVectorClassName[$A], $vectorClassName[$A]]
17 | with Serializable {
18 |
19 | ..${generateParVectorMethods()}
20 | }
21 | """
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/scala/codegen/parvector/parvectorclass/ParVectorCodeGen.scala:
--------------------------------------------------------------------------------
1 | package codegen
2 | package parvector
3 | package parvectorclass
4 |
5 | import iterator.ParVectorIteratorClassGen
6 | import vector.vectorpointer.VectorPointerCodeGen
7 |
8 | import scala.annotation.tailrec
9 | import scala.reflect.runtime.universe._
10 |
11 | trait ParVectorCodeGen {
12 | self: VectorProperties with VectorPointerCodeGen with ParVectorIteratorClassGen =>
13 |
14 | // Field names
15 |
16 | val par_vector = TermName("vector")
17 |
18 | // Method definitions
19 |
20 | protected def splitterCode() = {
21 | q"""
22 | val pit = new $parVectorIteratorClassName(0, $par_vector.length)
23 | pit.initIteratorFrom($par_vector)
24 | pit
25 | """
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/scala/codegen/parvector/parvectorclass/ParVectorMethodsGen.scala:
--------------------------------------------------------------------------------
1 | package codegen
2 | package parvector
3 | package parvectorclass
4 |
5 | import iterator.ParVectorIteratorClassGen
6 |
7 | import scala.reflect.runtime.universe._
8 |
9 | trait ParVectorMethodsGen {
10 | self: ParVectorCodeGen with ParVectorIteratorClassGen with VectorProperties =>
11 |
12 | def generateParVectorMethods() = {
13 | val methods = Seq(
14 | companionDef,
15 | thisDef,
16 | applyDef,
17 | lengthDef,
18 | splitterDef,
19 | seqDef,
20 | toVectorDef,
21 | generateParVectorIteratorClassDef())
22 | methods
23 | }
24 |
25 |
26 | private def companionDef =
27 | q"override def companion = $parVectorObjectTermName"
28 |
29 | private def thisDef =
30 | q"def this() = this($vectorObjectName.empty[$A])"
31 |
32 | private def applyDef =
33 | q"def apply(idx: Int) = $par_vector.apply(idx)"
34 |
35 | private def lengthDef = q"def length = $par_vector.length"
36 |
37 | private def splitterDef = {
38 | val code = splitterCode()
39 | q"def splitter: SeqSplitter[$A] = $code"
40 | }
41 |
42 | private def seqDef =
43 | q"override def seq: $vectorClassName[$A] = $par_vector"
44 |
45 |
46 | private def toVectorDef =
47 | q"override def toVector: Vector[$A] = $par_vector.toVector"
48 |
49 | }
50 |
51 |
--------------------------------------------------------------------------------
/src/main/scala/codegen/parvector/parvectorobject/ParVectorObjectClassGen.scala:
--------------------------------------------------------------------------------
1 | package codegen
2 | package parvector
3 | package parvectorobject
4 |
5 | import scala.reflect.runtime.universe._
6 |
7 | trait ParVectorObjectClassGen {
8 | self: ParVectorObjectMethodsGen with VectorProperties =>
9 |
10 | def generateParVectorObjectDef(): Tree = {
11 | q"""
12 | object $parVectorObjectTermName extends ParFactory[$parVectorClassName] {
13 | ..${generateParVectorObjectsMethods()}
14 | }
15 | """
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/scala/codegen/parvector/parvectorobject/ParVectorObjectMethodsGen.scala:
--------------------------------------------------------------------------------
1 | package codegen
2 | package parvector
3 | package parvectorobject
4 |
5 | import scala.reflect.runtime.universe._
6 |
7 | trait ParVectorObjectMethodsGen {
8 | self: VectorProperties =>
9 |
10 | def generateParVectorObjectsMethods() = {
11 | val methods = Seq(
12 | canBuildFromDef,
13 | newBuilderDef,
14 | newCombinerDef)
15 | methods
16 | }
17 |
18 |
19 | private def canBuildFromDef =
20 | q"implicit def canBuildFrom[$A]: CanCombineFrom[Coll, $A, $parVectorClassName[$A]] = new GenericCanCombineFrom[$A]"
21 |
22 | private def newBuilderDef =
23 | q"def newBuilder[$A]: Combiner[$A, $parVectorClassName[$A]] = newCombiner[$A]"
24 |
25 | private def newCombinerDef =
26 | q"def newCombiner[$A]: Combiner[$A, $parVectorClassName[$A]] = new $parVectorCombinerClassName[$A]"
27 |
28 | }
29 |
30 |
--------------------------------------------------------------------------------
/src/main/scala/codegen/test/VectorGeneratorGen.scala:
--------------------------------------------------------------------------------
1 | package codegen
2 | package test
3 |
4 | import codegen.vector.iterator.VectorIteratorCodeGen
5 |
6 | import scala.reflect.runtime.universe._
7 |
8 | trait VectorGeneratorGen {
9 | self: VectorProperties with VectorIteratorCodeGen =>
10 |
11 | def generateVectorGeneratorClass() = {
12 | inPackages(
13 | s"scala.collection.immutable.vectorutils.generated.$subpackage".split("\\."),
14 | q"""
15 | trait $vectorGeneratorClassName[$A] extends BaseVectorGenerator[$A] {
16 | import scala.collection.immutable.generated.$subpackage._
17 |
18 | override type Vec = ${vectorClassName}[$A]
19 |
20 | final def vectorClassName: String = ${vectorName()}
21 |
22 | override final def newBuilder() = $vectorObjectName.newBuilder[$A]
23 |
24 | override final def tabulatedVector(n: Int): Vec = $vectorObjectName.tabulate(n)(element)
25 |
26 | override final def rangedVector(start: Int, end: Int): Vec = $vectorObjectName.range(start, end) map element
27 |
28 | override final def emptyVector: Vec = $vectorObjectName.empty[A]
29 |
30 | override def iterator(vec: Vec, start: Int, end: Int) = {
31 | val it = new ${vectorIteratorClassName}[$A](start, end)
32 | it.$it_initIteratorFrom(vec)
33 | it
34 | }
35 |
36 | override final def plus(vec: Vec, elem: A): Vec = vec :+ elem
37 |
38 | override final def plus(elem: A, vec: Vec): Vec = vec.+:(elem)
39 |
40 | override final def plusPlus(vec1: Vec, vec2: Vec): Vec = vec1 ++ vec2
41 |
42 | override final def take(vec: Vec, n: Int): Vec = vec.take(n)
43 |
44 | override final def drop(vec: Vec, n: Int): Vec = vec.drop(n)
45 | }
46 | """)
47 | }
48 |
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/scala/codegen/test/VectorTestGen.scala:
--------------------------------------------------------------------------------
1 | package codegen
2 | package test
3 |
4 | import scala.reflect.runtime.universe._
5 |
6 | trait VectorTestGen {
7 | self: VectorProperties =>
8 |
9 | def generateVectorTestClasses() = {
10 | val name = vectorClassName.toString
11 |
12 | inPackages(
13 | s"scala.collection.immutable.vectortests.generated".split('.'),
14 | q"""
15 | package $subpackage {
16 | import scala.collection.immutable.vectorutils.generated.$subpackage._
17 | import scala.collection.immutable.vectortests._
18 | import scala.collection.immutable.vectorutils._
19 |
20 | abstract class $vectorTestClassName[A] extends VectorSpec[A] with $vectorGeneratorClassName[A]
21 |
22 | class ${TypeName(s"Int${name}Test")} extends $vectorTestClassName[Int] with VectorGeneratorType.IntGenerator
23 |
24 | class ${TypeName(s"String${name}Test")} extends $vectorTestClassName[String] with VectorGeneratorType.StringGenerator
25 | }
26 | """)
27 |
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/scala/codegen/vector/builder/VectorBuilderClassGen.scala:
--------------------------------------------------------------------------------
1 | package codegen
2 | package vector
3 | package builder
4 |
5 | import scala.reflect.runtime.universe._
6 |
7 | trait VectorBuilderClassGen {
8 | self: VectorBuilderMethodsGen with VectorProperties =>
9 |
10 | def generateVectorBuilderClassDef(): Tree = {
11 | q"""
12 | final class $vectorBuilderClassName[$A]()
13 | extends mutable.Builder[$A, $vectorClassName[$A]]
14 | with $vectorPointerClassName[$A @uncheckedVariance] {
15 | ..${generateVectorBuilderMethods()}
16 | }
17 | """
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/scala/codegen/vector/builder/VectorBuilderMethodsGen.scala:
--------------------------------------------------------------------------------
1 | package codegen
2 | package vector
3 | package builder
4 |
5 | import vectorpointer.VectorPointerCodeGen
6 |
7 | import scala.reflect.runtime.universe._
8 |
9 | trait VectorBuilderMethodsGen {
10 | self: VectorBuilderCodeGen with VectorPointerCodeGen with VectorProperties =>
11 |
12 | def generateVectorBuilderMethods() = {
13 | val statements = Seq(
14 | q"${displayAt(0)} = new Array[AnyRef]($blockWidth)",
15 | q"$depth = 1")
16 | val fields = Seq(
17 | q"private var $b_blockIndex = 0",
18 | q"private var $b_lo = 0",
19 | q"private var $b_acc: $vectorClassName[$A] = null")
20 |
21 | val methods = Seq(
22 | plusEqDef, plusPlusEqDef, resultDef, clearDef,
23 | b_endIndexDef, currentResultDef, clearCurrentDef)
24 |
25 | statements ++ fields ++ methods
26 | }
27 |
28 | protected def b_endIndexDef = {
29 | val code = b_endIndexCode()
30 | q"private[collection] def $endIndex = $code"
31 | }
32 |
33 | protected def plusEqDef = {
34 | val elem = TermName("elem")
35 | val code = plusEqCode(q"$elem")
36 | q"def $b_plusEq($elem: $A): this.type = $code"
37 | }
38 |
39 | protected def plusPlusEqDef = {
40 | val xs = TermName("xs")
41 | val code = plusPlusEqCode(xs)
42 | q"override def $b_plusPlusEq($xs: TraversableOnce[$A]): this.type = $code"
43 | }
44 |
45 | protected def resultDef = {
46 | val code = resultCode()
47 | q"def $b_result(): $vectorClassName[$A] = $code"
48 | }
49 |
50 | protected def clearDef = q"def $b_clear(): Unit = ${clearCode()}"
51 |
52 | protected def currentResultDef = {
53 | val code = currentResultCode()
54 | q"private def $b_currentResult(): $vectorClassName[$A] = $code"
55 | }
56 | protected def clearCurrentDef = q"private def $b_clearCurrent(): Unit = ${clearCurrentCode()}"
57 |
58 | }
59 |
60 |
--------------------------------------------------------------------------------
/src/main/scala/codegen/vector/iterator/VectorIteratorClassGen.scala:
--------------------------------------------------------------------------------
1 | package codegen
2 | package vector
3 | package iterator
4 |
5 | import vectorpointer.VectorPointerCodeGen
6 |
7 | import scala.reflect.runtime.universe._
8 |
9 | trait VectorIteratorClassGen {
10 | self: VectorIteratorMethodsGen with VectorProperties with VectorIteratorCodeGen with VectorPointerCodeGen =>
11 |
12 | def generateVectorIteratorClassDef(): Tree = {
13 | q"""
14 | class $vectorIteratorClassName[+$A]($it_iteratorStartIndex: Int, override private[immutable] val $endIndex: Int)
15 | extends AbstractIterator[$A]
16 | with Iterator[$A]
17 | with $vectorPointerClassName[$A @uncheckedVariance] {
18 |
19 | ..${generateVectorIteratorMethods()}
20 | }
21 | """
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/scala/codegen/vector/iterator/VectorIteratorMethodsGen.scala:
--------------------------------------------------------------------------------
1 | package codegen
2 | package vector
3 | package iterator
4 |
5 | import vectorpointer.VectorPointerCodeGen
6 |
7 | import scala.reflect.runtime.universe._
8 |
9 | trait VectorIteratorMethodsGen {
10 | self: VectorIteratorCodeGen with VectorPointerCodeGen with VectorProperties =>
11 |
12 | def generateVectorIteratorMethods() = {
13 | val fields = Seq(
14 | q"private var $it_blockIndex: Int = _",
15 | q"private var $it_lo: Int = _",
16 | q"private var $it_endLo: Int = _",
17 | q"private var $it_hasNextVar: Boolean = _"
18 | )
19 | val methods = Seq(initIteratorFromDef, hasNextDef, nextDef, remainingDef)
20 |
21 | fields ++ methods
22 | }
23 |
24 |
25 | protected def initIteratorFromDef = {
26 | val that = TermName("that")
27 | val code = initIteratorFromCode(that)
28 | q"private[collection] final def $it_initIteratorFrom[$B >: $A](that: $vectorPointerClassName[$B]): Unit = $code"
29 | }
30 |
31 | protected def hasNextDef = q"final def $it_hasNext = $it_hasNextVar"
32 |
33 | protected def nextDef = {
34 | val code = nextCode()
35 | q"def next(): A = $code"
36 | }
37 |
38 | private def remainingDef = {
39 | val code = remainingCode()
40 | q"private[collection] def $it_remaining: Int = $code"
41 | }
42 |
43 | }
44 |
45 |
--------------------------------------------------------------------------------
/src/main/scala/codegen/vector/reverseiterator/VectorReverseIteratorClassGen.scala:
--------------------------------------------------------------------------------
1 | package codegen
2 | package vector
3 | package reverseiterator
4 |
5 | import vectorpointer.VectorPointerCodeGen
6 |
7 | import scala.reflect.runtime.universe._
8 |
9 | trait VectorReverseIteratorClassGen {
10 | self: VectorReverseIteratorMethodsGen with VectorProperties with VectorReverseIteratorCodeGen with VectorPointerCodeGen =>
11 |
12 | def generateVectorReverseIteratorClassDef(): Tree = {
13 | q"""
14 | class $vectorReverseIteratorClassName[+$A]($rit_startIndex: Int, override private[immutable] final val $endIndex: Int)
15 | extends AbstractIterator[$A]
16 | with Iterator[$A]
17 | with $vectorPointerClassName[$A @uncheckedVariance] {
18 |
19 | ..${generateVectorReverseIteratorMethods()}
20 | }
21 | """
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/scala/codegen/vector/reverseiterator/VectorReverseIteratorCodeGen.scala:
--------------------------------------------------------------------------------
1 | package codegen
2 | package vector
3 | package reverseiterator
4 |
5 | import vector.vectorpointer.VectorPointerCodeGen
6 |
7 | import scala.reflect.runtime.universe._
8 |
9 | trait VectorReverseIteratorCodeGen {
10 | self: VectorProperties with VectorPointerCodeGen =>
11 |
12 |
13 | // Field names
14 |
15 | val rit_startIndex = TermName("startIndex")
16 |
17 | val rit_lastIndexOfBlock = TermName("lastIndexOfBlock")
18 | val rit_lo = TermName("lo")
19 | val rit_endLo = TermName("endLo")
20 | val rit_hasNextVar = TermName("_hasNext")
21 |
22 |
23 | // Method names
24 |
25 | val rit_hasNext = TermName("hasNext")
26 | val rit_next = TermName("next")
27 | val rit_initIteratorFrom = TermName("initIteratorFrom")
28 |
29 |
30 | // Method definitions
31 |
32 | protected def rit_initIteratorFromCode(that: TermName) = {
33 | q"""
34 | ..${assertions(q"0 <= $rit_startIndex", q"$rit_startIndex <= $endIndex", q"$endIndex <= $that.$endIndex")}
35 | $initWithFocusFrom($that)
36 | $rit_hasNextVar = $rit_startIndex < $endIndex
37 | if ($rit_hasNextVar) {
38 | val idx = $endIndex - 1
39 | $focusOn(idx)
40 | $rit_lastIndexOfBlock = idx
41 | $rit_lo = (idx - focusStart) & $blockMask
42 | $rit_endLo = math.max($rit_startIndex - $focusStart - $rit_lastIndexOfBlock, 0)
43 | }
44 | else {
45 | $rit_lastIndexOfBlock = 0
46 | $rit_lo = 0
47 | $rit_endLo = 0
48 | ${displayAt(0)} = new Array[AnyRef](1)
49 | }
50 | """
51 | }
52 |
53 | protected def rit_nextCode() = {
54 | q"""
55 | if ($rit_hasNextVar) {
56 | val res = ${displayAt(0)}($rit_lo).asInstanceOf[$A]
57 | $rit_lo -= 1
58 | if ($rit_lo >= $rit_endLo) {
59 | res
60 | } else {
61 | val newBlockIndex = $rit_lastIndexOfBlock - $blockWidth
62 | if ($focusStart <= newBlockIndex) {
63 | val _focusStart = $focusStart
64 | val newBlockIndexInFocus = newBlockIndex - _focusStart
65 | $gotoPrevBlockStart(newBlockIndexInFocus, newBlockIndexInFocus ^ ($rit_lastIndexOfBlock - _focusStart))
66 | $rit_lastIndexOfBlock = newBlockIndex
67 | $rit_lo = $blockMask
68 | $rit_endLo = math.max($rit_startIndex - $focusStart - $focus, 0)
69 | res
70 | } else if (startIndex < $focusStart) {
71 | val newIndex = $focusStart - 1
72 | $focusOn(newIndex)
73 | $rit_lastIndexOfBlock = newIndex
74 | $rit_lo = (newIndex - $focusStart) & $blockMask
75 | $rit_endLo = math.max($rit_startIndex - $focusStart - $rit_lastIndexOfBlock, 0)
76 | res
77 | } else {
78 | $rit_hasNextVar = false
79 | res
80 | }
81 | }
82 | } else {
83 | throw new NoSuchElementException("reached iterator end")
84 | }
85 | """
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/src/main/scala/codegen/vector/reverseiterator/VectorReverseIteratorMethodsGen.scala:
--------------------------------------------------------------------------------
1 | package codegen
2 | package vector
3 | package reverseiterator
4 |
5 | import vectorpointer.VectorPointerCodeGen
6 |
7 | import scala.reflect.runtime.universe._
8 |
9 | trait VectorReverseIteratorMethodsGen {
10 | self: VectorReverseIteratorCodeGen with VectorPointerCodeGen with VectorProperties =>
11 |
12 | def generateVectorReverseIteratorMethods() = {
13 | val fields = Seq(
14 | q"private var $rit_lastIndexOfBlock: Int = _",
15 | q"private var $rit_lo: Int = _",
16 | q"private var $rit_endLo: Int = _",
17 | q"private var $rit_hasNextVar: Boolean = $rit_startIndex < $endIndex")
18 |
19 | val methods = Seq(rit_initIteratorFromDef, rit_hasNextDef, rit_nextDef)
20 |
21 | fields ++ methods
22 | }
23 |
24 |
25 | protected def rit_initIteratorFromDef = {
26 | val that = TermName("that")
27 | val code = rit_initIteratorFromCode(that)
28 | q"private[collection] final def $rit_initIteratorFrom[$B >: $A]($that: $vectorPointerClassName[$B]): Unit = $code"
29 | }
30 |
31 | protected def rit_hasNextDef = q"final def $rit_hasNext = $rit_hasNextVar"
32 |
33 | protected def rit_nextDef = {
34 | val code = rit_nextCode()
35 | q"def next(): $A = $code"
36 | }
37 |
38 |
39 | }
40 |
41 |
--------------------------------------------------------------------------------
/src/main/scala/codegen/vector/vectorclass/VectorClassGen.scala:
--------------------------------------------------------------------------------
1 | package codegen
2 | package vector
3 | package vectorclass
4 |
5 | import scala.reflect.runtime.universe._
6 |
7 | trait VectorClassGen {
8 | self: VectorMethodsGen with VectorProperties with VectorCodeGen =>
9 |
10 | def generateVectorClassDef(): Tree = {
11 | q"""
12 | final class $vectorClassName[+$A] private[immutable](override private[immutable] val $v_endIndex: Int)
13 | extends scala.collection.AbstractSeq[$A]
14 | with scala.collection.immutable.IndexedSeq[$A]
15 | with scala.collection.generic.GenericTraversableTemplate[$A, $vectorClassName]
16 | with scala.collection.IndexedSeqLike[$A, $vectorClassName[$A]]
17 | with $vectorPointerClassName[$A @uncheckedVariance]
18 | with Serializable {
19 | self =>
20 | ..${generateVectorMethods()}
21 | }
22 | """
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/scala/codegen/vector/vectorobject/VectorObjectClassGen.scala:
--------------------------------------------------------------------------------
1 | package codegen
2 | package vector
3 | package vectorobject
4 |
5 | import scala.reflect.runtime.universe._
6 |
7 | trait VectorObjectClassGen {
8 | self: VectorObjectMethodsGen with VectorProperties =>
9 |
10 | def generateVectorObjectClassDef() = {
11 | q"""
12 | object $vectorObjectName extends scala.collection.generic.IndexedSeqFactory[$vectorClassName] {
13 | ..${generateVectorObjectMethods()}
14 | }
15 | """
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/scala/codegen/vector/vectorobject/VectorObjectCodeGen.scala:
--------------------------------------------------------------------------------
1 | package codegen
2 | package vector
3 | package vectorobject
4 |
5 | import vectorpointer.VectorPointerCodeGen
6 |
7 | import scala.reflect.runtime.universe._
8 |
9 | trait VectorObjectCodeGen {
10 | self: VectorProperties with VectorPointerCodeGen =>
11 |
12 | // Methods names
13 | val o_empty = TermName("empty")
14 | val o_emptyTransientBlock = TermName("emptyTransientBlock")
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/scala/codegen/vector/vectorobject/VectorObjectMethodsGen.scala:
--------------------------------------------------------------------------------
1 | package codegen
2 | package vector
3 | package vectorobject
4 |
5 | import scala.reflect.runtime.universe._
6 |
7 | trait VectorObjectMethodsGen {
8 | self: VectorObjectCodeGen with VectorProperties =>
9 |
10 | def generateVectorObjectMethods() = {
11 | Seq(
12 | newBuilderDef(),
13 | canBuildFromDef(),
14 | q"private lazy val EMPTY_VECTOR = new $vectorClassName[Nothing](0)",
15 | q"override def $o_empty[$A]: $vectorClassName[$A] = EMPTY_VECTOR",
16 | q"private[immutable] final lazy val $o_emptyTransientBlock = new Array[AnyRef](${1 + blockInvariants})"
17 | )
18 | }
19 |
20 | private def newBuilderDef() =
21 | q"def newBuilder[$A]: mutable.Builder[$A, $vectorClassName[$A]] = new $vectorBuilderClassName[$A]"
22 |
23 | private def canBuildFromDef() =
24 | q"implicit def canBuildFrom[$A]: scala.collection.generic.CanBuildFrom[Coll, $A, $vectorClassName[$A]] = ReusableCBF.asInstanceOf[GenericCanBuildFrom[$A]]"
25 | }
26 |
27 |
--------------------------------------------------------------------------------
/src/main/scala/codegen/vector/vectorpointer/VectorPointerClassGen.scala:
--------------------------------------------------------------------------------
1 | package codegen
2 | package vector
3 | package vectorpointer
4 |
5 | import scala.reflect.runtime.universe._
6 |
7 | trait VectorPointerClassGen {
8 | self: VectorPointerMethodsGen with VectorProperties =>
9 |
10 | def generateVectorPointerClassDef(): Tree = {
11 | q"""
12 | private[immutable] trait $vectorPointerClassName[$A] {
13 | ..${generateVectorPointerMethods()}
14 | }
15 | """
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/scala/scala/collection/immutable/fingertree/FingerTreeSeq.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.fingertree
2 |
3 | import scala.collection.mutable.Builder
4 | import scala.collection.{GenTraversableOnce, IndexedSeqLike, AbstractSeq}
5 | import scala.collection.generic.{IndexedSeqFactory, CanBuildFrom, GenericCompanion, GenericTraversableTemplate}
6 | import scala.collection.immutable.IndexedSeq
7 |
8 |
9 | /**
10 | * Created by nicolasstucki on 01/02/15.
11 | */
12 |
13 | final class FingerTreeSeq[+A] private[immutable](private[immutable] val fingerTree: FingerTreeIndexedSeq[AnyRef])
14 | extends AbstractSeq[A]
15 | with IndexedSeq[A]
16 | with GenericTraversableTemplate[A, FingerTreeSeq]
17 | with IndexedSeqLike[A, FingerTreeSeq[A]] {
18 | self =>
19 | private implicit val measure = Measure.Indexed
20 |
21 | override def companion: GenericCompanion[FingerTreeSeq] = FingerTreeSeq
22 |
23 | override def length = fingerTree.size
24 |
25 |
26 | override def lengthCompare(len: Int) = length - len
27 |
28 |
29 | override def apply(idx: Int) = fingerTree.apply(idx).asInstanceOf[A]
30 |
31 | override def +:[B >: A, That](elem: B)(implicit bf: CanBuildFrom[FingerTreeSeq[A], B, That]): That =
32 | if (bf eq IndexedSeq.ReusableCBF)
33 | new FingerTreeSeq[B](elem.asInstanceOf[AnyRef] +: fingerTree).asInstanceOf[That]
34 | else super.+:(elem)(bf)
35 |
36 | override def :+[B >: A, That](elem: B)(implicit bf: CanBuildFrom[FingerTreeSeq[A], B, That]): That =
37 | if (bf eq IndexedSeq.ReusableCBF)
38 | new FingerTreeSeq[B](fingerTree :+ elem.asInstanceOf[AnyRef]).asInstanceOf[That]
39 | else super.:+(elem)(bf)
40 |
41 | override def ++[B >: A, That](that: GenTraversableOnce[B])(implicit bf: CanBuildFrom[FingerTreeSeq[A], B, That]): That = {
42 | if (that.isInstanceOf[FingerTreeSeq[B]]) {
43 | new FingerTreeSeq[B](fingerTree ++ that.asInstanceOf[FingerTreeSeq[B]].fingerTree).asInstanceOf[That]
44 | } else super.++(that)
45 | }
46 |
47 | override def updated[B >: A, That](index: Int, elem: B)(implicit bf: CanBuildFrom[FingerTreeSeq[A], B, That]) = {
48 | if (bf eq IndexedSeq.ReusableCBF) {
49 | val (init, tail) = fingerTree.splitAt(index)
50 | new FingerTreeSeq[B](
51 | (init :+ elem.asInstanceOf[AnyRef]) ++ tail
52 | ).asInstanceOf[That]
53 | } else
54 | super.updated(index, elem)
55 | }
56 |
57 |
58 | override def iterator = fingerTree.iterator map (_.asInstanceOf[A])
59 |
60 | override def head = {
61 | if (isEmpty) throw new UnsupportedOperationException
62 | super.head
63 | }
64 |
65 | override def last = {
66 | if (isEmpty) throw new UnsupportedOperationException
67 | super.last
68 | }
69 | }
70 |
71 | final class FingerTreeSeqBuilder[A]() extends Builder[A, FingerTreeSeq[A]] {
72 | var fingerTree = FingerTreeIndexedSeq.empty[AnyRef]
73 |
74 | override def +=(elem: A) = {
75 | fingerTree = fingerTree :+ elem.asInstanceOf[AnyRef]
76 | this
77 | }
78 |
79 | override def result() = new FingerTreeSeq[A](fingerTree)
80 |
81 | override def clear() = {
82 | fingerTree = FingerTreeIndexedSeq.empty[AnyRef]
83 | }
84 | }
85 |
86 | object FingerTreeSeq extends IndexedSeqFactory[FingerTreeSeq] {
87 | def newBuilder[A]: Builder[A, FingerTreeSeq[A]] = new FingerTreeSeqBuilder[A]
88 |
89 | implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, FingerTreeSeq[A]] =
90 | ReusableCBF.asInstanceOf[GenericCanBuildFrom[A]]
91 |
92 | override def empty[A]: FingerTreeSeq[A] = new FingerTreeSeq(FingerTreeIndexedSeq.empty[AnyRef])
93 |
94 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/BaseVectorBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable
2 | package vectorbenchmarks
3 |
4 | import org.scalameter.PerformanceTest.OfflineRegressionReport
5 | import org.scalameter._
6 | import org.scalameter.utils.Tree
7 |
8 | import scala.collection.immutable.vectorutils.BaseVectorGenerator
9 |
10 |
11 | trait BaseVectorBenchmark[A] extends OfflineRegressionReport with BaseVectorGenerator[A] {
12 |
13 | /* config */
14 |
15 | def minHeight = 4
16 |
17 | def maxHeight = 4
18 |
19 | def points = 8
20 |
21 | def independentSamples = 16
22 |
23 | def benchRunsPerSample = 128
24 |
25 | def benchRuns = independentSamples * benchRunsPerSample
26 |
27 | def memoryInHeapSeq = Seq("16g") //, "512m")
28 |
29 | def generateVectorsFixedSum(sum: Int): Gen[(Vec, Vec)] = {
30 | val min = sum / points
31 | val max = sum - min
32 | for {
33 | size <- sizes(min, max, (max - min) / points, "size")
34 | } yield (tabulatedVector(size), tabulatedVector(sum - size))
35 | }
36 |
37 | def generateVectorsFixedLHS(fixedSize: Int, from: Int, to: Int, by: Int): Gen[(Vec, Vec)] = {
38 | for {
39 | size <- sizes(from, to, by, "size")
40 | } yield (tabulatedVector(fixedSize), tabulatedVector(size))
41 | }
42 |
43 | def generateVectorsFixedRHS(fixedSize: Int, from: Int, to: Int, by: Int): Gen[(Vec, Vec)] = {
44 | for {
45 | size <- sizes(from, to, by, "size")
46 | } yield (tabulatedVector(size), tabulatedVector(fixedSize))
47 | }
48 |
49 | /* data */
50 |
51 | def sizes(from: Int, to: Int, by: Int, sizesName: String) = {
52 | def expSeq(current: Int, seq: List[Int] = Nil): List[Int] =
53 | if (current <= to) {
54 | val newVal = (1.5 * current).toInt
55 | expSeq(newVal, newVal :: seq)
56 | } else (1.5 * current).toInt :: seq
57 | Gen.enumeration(sizesName)(expSeq(4): _*)
58 | // Gen.range(sizesName)(to - 1, from, -by)
59 | }
60 |
61 | def sized[T, Repr](g: Gen[Repr])(implicit ev: Repr <:< Traversable[T]): Gen[(Int, Repr)] = for (xs <- g) yield (xs.size, xs)
62 |
63 | /* sequences */
64 |
65 | def generateVectors(from: Int, to: Int, by: Int, sizesName: String = "sizes"): Gen[Vec]
66 |
67 | def fromToBy(height: Int) = (
68 | math.pow(32, height - 1).toInt + 1,
69 | math.pow(32, height).toInt,
70 | math.max(math.pow(32, height).toInt / points, 1)
71 | )
72 |
73 | def performanceOfVectors(benchmarks: Int => Unit): Unit = {
74 | for (memoryInHeap <- memoryInHeapSeq) {
75 | performance of s"$vectorName benchmarks (-Xms$memoryInHeap -Xmx$memoryInHeap)" config(
76 | Key.exec.benchRuns -> benchRuns,
77 | // Key.verbose -> false,
78 | Key.exec.independentSamples -> independentSamples,
79 | Key.exec.jvmflags -> s"-Xms$memoryInHeap -Xmx$memoryInHeap" // "-XX:+UnlockDiagnosticVMOptions -XX:+PrintInlining" "-XX:+PrintCompilation",
80 | ) in {
81 | for (height <- maxHeight to minHeight by -1) {
82 | benchmarks(height)
83 | }
84 | }
85 | }
86 | }
87 | }
88 |
89 |
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/CSVReporter.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks
2 |
3 | import java.text.SimpleDateFormat
4 | import java.util.Calendar
5 |
6 | import org.scalameter._
7 | import org.scalameter.utils.Tree
8 |
9 | import scala.collection._
10 |
11 | /**
12 | * Created by nicolasstucki on 02/02/15.
13 | */
14 | object CSVReporter extends Reporter {
15 |
16 | def report(result: CurveData, persistor: Persistor) {}
17 |
18 | def report(results: Tree[CurveData], persistor: Persistor) = {
19 | val times = scala.collection.mutable.Map.empty[(List[(String, Any)], String), String]
20 | val curves = scala.collection.mutable.Map.empty[String, String]
21 | val scopes = scala.collection.mutable.SortedSet.empty[String]
22 | val scopeFiles = scala.collection.mutable.SortedSet.empty[String]
23 | val params = scala.collection.mutable.Set.empty[List[(String, Any)]]
24 |
25 | for (result <- results) {
26 | for (measurement <- result.measurements) {
27 | val scopeFile = result.context.scope.replace(result.context.curve, "").replace("benchmarks (-Xms16g -Xmx16g)", "").replaceAll("Height [0-9]", "") + " "
28 | val scopeName = scopeFile + result.context.curve
29 |
30 | val _params = measurement.params.axisData.toList
31 | params += _params
32 | times((_params, scopeName)) = measurement.value.toString
33 | scopes += scopeName
34 | scopeFiles += scopeFile
35 | curves(scopeName) = result.context.curve
36 | }
37 | }
38 |
39 | implicit val ordInt = new Ordering[List[Int]] {
40 | override def compare(xs: List[Int], ys: List[Int]) = (xs, ys) match {
41 | case (x :: xs, y :: ys) =>
42 | val cmp = x compare y
43 | if (cmp == 0) compare(xs, ys)
44 | else cmp
45 | case (x :: xs, Nil) => -1
46 | case (Nil, y :: ys) => 1
47 | case (Nil, Nil) => 0
48 | }
49 | }
50 | for (scopeFile <- scopeFiles) {
51 | val sb = new StringBuilder()
52 | // sb ++= ", " ++= scopes.toList.filter(_.startsWith(scopeFile)).map(scope => scope.replace(curves(scope), "")).mkString("", ", ", "\n")
53 |
54 | sb ++= params.head.map(_._1).mkString(", ") ++= ", " ++= scopes.iterator.filter(_.startsWith(scopeFile)).map(curves(_).replace("[Int]", " ")).mkString("", ", ", "\n")
55 | for (param <- params.toList.sortBy(_.map(a => Integer.parseInt(a._2.toString)))) {
56 | sb ++= param.map(_._2).mkString(", ")
57 | sb ++= scopes.iterator.filter(_.startsWith(scopeFile)).map(scope => times.getOrElse((param, scope), "")).fold("")((a, b) => s"$a, $b") += '\n'
58 | }
59 |
60 | import java.io._
61 | val dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm")
62 | val dateTime = dateTimeFormat.format(Calendar.getInstance().getTime)
63 | val file = new File(s"./benchmarks_outputs/${scopeFile.replaceFirst("W*", "")} $dateTime.csv")
64 | val bw = new BufferedWriter(new FileWriter(file))
65 | bw.write(sb.result())
66 | bw.close()
67 |
68 | log(sb.result())
69 | }
70 | true
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/cowarray/CowArrayAppendBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.cowarray
2 |
3 | import scala.collection.immutable.cowarray.CowArray
4 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.AppendBenchmarks
5 | import scala.collection.immutable.vectorutils.VectorGeneratorType
6 |
7 | abstract class CowArrayAbstractAppendBenchmark[A] extends AppendBenchmarks[A] with CowArrayBenchmark[A]
8 |
9 | class CowArrayAppendIntBenchmark extends CowArrayAbstractAppendBenchmark[Int] with VectorGeneratorType.IntGenerator {
10 |
11 | def append(vec: CowArray[Int], n: Int): Int = {
12 | var v = vec
13 | var i = 0
14 | while (i < n) {
15 | v = vec :+ 0
16 | i += 1
17 | }
18 | v.length
19 | }
20 |
21 | }
22 |
23 | class CowArrayAppendStringBenchmark extends CowArrayAbstractAppendBenchmark[String] with VectorGeneratorType.StringGenerator {
24 | val ref = ""
25 |
26 | def append(vec: CowArray[String], n: Int): Int = {
27 | var v = vec
28 | var i = 0
29 | while (i < n) {
30 | v = vec :+ ref
31 | i += 1
32 | }
33 | v.length
34 | }
35 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/cowarray/CowArrayApplyBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.cowarray
2 |
3 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.ApplyBenchmarks
4 | import scala.collection.immutable.vectorutils.VectorGeneratorType
5 |
6 |
7 | abstract class CowArrayAbstractApplyBenchmark[A] extends ApplyBenchmarks[A] with CowArrayBenchmark[A]
8 |
9 | class CowArrayApplyIntBenchmark extends CowArrayAbstractApplyBenchmark[Int] with VectorGeneratorType.IntGenerator
10 |
11 | class CowArrayApplyStringBenchmark extends CowArrayAbstractApplyBenchmark[String] with VectorGeneratorType.StringGenerator
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/cowarray/CowArrayBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.cowarray
2 |
3 | import org.scalameter.Gen
4 |
5 | import scala.collection.immutable.cowarray._
6 | import scala.collection.immutable.vectorbenchmarks.BaseVectorBenchmark
7 | import scala.collection.immutable.vectorutils._
8 |
9 | trait CowArrayBenchmark[A] extends BaseVectorBenchmark[A] with CowArrayGenerator[A] {
10 |
11 | override def generateVectors(from: Int, to: Int, by: Int, sizesName: String): Gen[CowArray[A]] =
12 | for {
13 | size <- sizes(from, to, by, sizesName)
14 | } yield tabulatedVector(size)
15 |
16 |
17 | def generateVectors2(from: Int, to: Int, by: Int): Gen[(Vec, Vec)] = {
18 | for {
19 | size1 <- sizes(from, to, by, "size1")
20 | size2 <- sizes(from, to, by, "size2")
21 | } yield (tabulatedVector(size1), tabulatedVector(size2))
22 | }
23 |
24 | }
25 |
26 | trait CowArrayGenerator[A] extends BaseVectorGenerator[A] {
27 | override final type Vec = CowArray[A]
28 |
29 | final def vectorClassName: String = "CowArray"
30 |
31 |
32 | override final def newBuilder() = CowArray.newBuilder[A]
33 |
34 | override final def tabulatedVector(n: Int): Vec =
35 | CowArray.tabulate(n)(element)
36 |
37 | override final def rangedVector(start: Int, end: Int): Vec =
38 | CowArray.range(start, end) map element
39 |
40 | override final def emptyVector: Vec = CowArray.empty[A]
41 |
42 | override def iterator(vec: Vec, start: Int, end: Int) = vec.take(end).drop(start).iterator
43 |
44 | override def plus(vec: Vec, elem: A): Vec = vec :+ elem
45 |
46 | override def plus(elem: A, vec: Vec): Vec = elem +: vec
47 |
48 | override final def plusPlus(vec1: Vec, vec2: Vec): Vec = vec1 ++ vec2
49 |
50 | override final def take(vec: Vec, n: Int): Vec = vec.take(n)
51 |
52 | override final def drop(vec: Vec, n: Int): Vec = vec.drop(n)
53 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/cowarray/CowArrayBuilderBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.cowarray
2 |
3 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.BuilderBenchmarks
4 | import scala.collection.immutable.vectorutils.VectorGeneratorType
5 |
6 | import scala.collection.immutable.cowarray._
7 |
8 | abstract class CowArrayAbstractBuilderBenchmark[A] extends BuilderBenchmarks[A] with CowArrayBenchmark[A] {
9 | def buildVector(n: Int): Int = {
10 | var i = 0
11 | var b = CowArray.newBuilder[A]
12 | val e = element(0)
13 | while (i < n) {
14 | b += e
15 | i += 1
16 |
17 | }
18 | b.result().length
19 | }
20 | }
21 |
22 | class CowArrayBuilderIntBenchmark extends CowArrayAbstractBuilderBenchmark[Int] with VectorGeneratorType.IntGenerator
23 |
24 | class CowArrayBuilderStringBenchmark extends CowArrayAbstractBuilderBenchmark[String] with VectorGeneratorType.StringGenerator
25 |
26 |
27 | abstract class CowArrayAbstractBuilderHintedBenchmark[A] extends BuilderBenchmarks[A] with CowArrayBenchmark[A] {
28 |
29 | override def vectorName = super.vectorName + "Hinted"
30 |
31 | def buildVector(n: Int): Int = {
32 | var i = 0
33 | var b = CowArray.newBuilder[A]
34 | b.sizeHint(n)
35 | val e = element(0)
36 | while (i < n) {
37 | b += e
38 | i += 1
39 |
40 | }
41 | b.result().length
42 | }
43 | }
44 |
45 | class CowArrayBuilderHintedIntBenchmark extends CowArrayAbstractBuilderHintedBenchmark[Int] with VectorGeneratorType.IntGenerator
46 |
47 | class CowArrayBuilderHintedStringBenchmark extends CowArrayAbstractBuilderHintedBenchmark[String] with VectorGeneratorType.StringGenerator
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/cowarray/CowArrayConcatenationBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.cowarray
2 |
3 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.ConcatenationBenchmarks
4 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.Concatenation2Benchmarks
5 | import scala.collection.immutable.vectorutils.VectorGeneratorType
6 |
7 | abstract class CowArrayAbstractConcatenationBenchmark[A] extends ConcatenationBenchmarks[A] with CowArrayBenchmark[A]
8 |
9 | class CowArrayConcatenationIntBenchmark extends CowArrayAbstractConcatenationBenchmark[Int] with VectorGeneratorType.IntGenerator
10 |
11 | class CowArrayConcatenationStringBenchmark extends CowArrayAbstractConcatenationBenchmark[String] with VectorGeneratorType.StringGenerator
12 |
13 |
14 | abstract class CowArrayAbstractConcatenation2Benchmark[A] extends Concatenation2Benchmarks[A] with CowArrayBenchmark[A]
15 |
16 | class CowArrayConcatenation2IntBenchmark extends CowArrayAbstractConcatenation2Benchmark[Int] with VectorGeneratorType.IntGenerator
17 |
18 | class CowArrayConcatenation2StringBenchmark extends CowArrayAbstractConcatenation2Benchmark[String] with VectorGeneratorType.StringGenerator
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/cowarray/CowArrayIterationBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.cowarray
2 |
3 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.IterationBenchmarks
4 | import scala.collection.immutable.vectorutils.VectorGeneratorType
5 |
6 | abstract class CowArrayAbstractIterationBenchmark[A] extends IterationBenchmarks[A] with CowArrayBenchmark[A]
7 |
8 | class CowArrayIterationIntBenchmark extends CowArrayAbstractIterationBenchmark[Int] with VectorGeneratorType.IntGenerator
9 |
10 | class CowArrayIterationStringBenchmark extends CowArrayAbstractIterationBenchmark[String] with VectorGeneratorType.StringGenerator
11 |
12 |
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/cowarray/CowArrayMemoryAllocation.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.cowarray
2 |
3 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.MemoryAllocation
4 | import scala.collection.immutable.vectorutils.VectorGeneratorType
5 |
6 |
7 | abstract class CowArrayAbstractMemoryAllocation[A] extends MemoryAllocation[A] with CowArrayBenchmark[A]
8 |
9 | class CowArrayIntMemoryAllocation extends CowArrayAbstractMemoryAllocation[Int] with VectorGeneratorType.IntGenerator
10 |
11 | class CowArrayStringMemoryAllocation extends CowArrayAbstractMemoryAllocation[String] with VectorGeneratorType.StringGenerator
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/cowarray/CowArrayPrependBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.cowarray
2 |
3 | import scala.collection.immutable.cowarray.CowArray
4 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.PrependBenchmarks
5 | import scala.collection.immutable.vectorutils._
6 |
7 | abstract class CowArrayAbstractPrependBenchmark[A] extends PrependBenchmarks[A] with CowArrayBenchmark[A]
8 |
9 | class CowArrayPrependIntBenchmark extends CowArrayAbstractPrependBenchmark[Int] with VectorGeneratorType.IntGenerator {
10 |
11 | def prepend(vec: CowArray[Int], n: Int, times: Int): Int = {
12 | var i = 0
13 | var v: CowArray[Int] = vec
14 | var sum = 0
15 | while (i < times) {
16 | v = vec
17 | var j = 0
18 | while (j < n) {
19 | v = 0 +: vec
20 | j += 1
21 | }
22 | sum += v.length
23 | i += 1
24 | }
25 | sum
26 | }
27 |
28 | }
29 |
30 | class CowArrayPrependStringBenchmark extends CowArrayAbstractPrependBenchmark[String] with VectorGeneratorType.StringGenerator {
31 | val ref = ""
32 |
33 | def prepend(vec: CowArray[String], n: Int, times: Int): Int = {
34 | var i = 0
35 | var v: CowArray[String] = null
36 | var sum = 0
37 | while (i < times) {
38 | v = vec
39 | var j = 0
40 | while (j < n) {
41 | v = ref +: vec
42 | j += 1
43 | }
44 | sum += v.length
45 | i += 1
46 | }
47 | sum
48 | }
49 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/cowarray/CowArraySplitBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.cowarray
2 |
3 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.SplitBenchmarks
4 | import scala.collection.immutable.vectorutils.VectorGeneratorType
5 |
6 |
7 | abstract class CowArrayAbstractSplitBenchmark[A] extends SplitBenchmarks[A] with CowArrayBenchmark[A]
8 |
9 | class CowArraySplitIntBenchmark extends CowArrayAbstractSplitBenchmark[Int] with VectorGeneratorType.IntGenerator
10 |
11 | class CowArraySplitStringBenchmark extends CowArrayAbstractSplitBenchmark[String] with VectorGeneratorType.StringGenerator
12 |
13 |
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/cowarray/CowArrayUpdateBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.cowarray
2 |
3 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.UpdateBenchmarks
4 | import scala.collection.immutable.vectorutils.VectorGeneratorType
5 |
6 |
7 | abstract class CowArrayAbstractUpdateBenchmark[A] extends UpdateBenchmarks[A] with CowArrayBenchmark[A] {
8 | override def to(n: Int): Int = math.min(n, 92171)
9 | }
10 |
11 | class CowArrayUpdateIntBenchmark extends CowArrayAbstractUpdateBenchmark[Int] with VectorGeneratorType.IntGenerator
12 |
13 | class CowArrayUpdateStringBenchmark extends CowArrayAbstractUpdateBenchmark[String] with VectorGeneratorType.StringGenerator
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/fingertree/FingerTreeAppendBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.fingertree
2 |
3 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.AppendBenchmarks
4 | import scala.collection.immutable.vectorutils.VectorGeneratorType
5 | import scala.collection.immutable.fingertree.FingerTreeSeq
6 |
7 | abstract class FingerTreeAbstractAppendBenchmark[A] extends AppendBenchmarks[A] with FingerTreeBenchmark[A]
8 |
9 | class FingerTreeAppendIntBenchmark extends FingerTreeAbstractAppendBenchmark[Int] with VectorGeneratorType.IntGenerator {
10 |
11 | def append(vec: FingerTreeSeq[Int], n: Int): Int = {
12 | var v = vec
13 | var i = 0
14 | while (i < n) {
15 | v = vec :+ 0
16 | i += 1
17 | }
18 | v.length
19 | }
20 |
21 | }
22 |
23 | class FingerTreeAppendStringBenchmark extends FingerTreeAbstractAppendBenchmark[String] with VectorGeneratorType.StringGenerator {
24 | val ref = ""
25 |
26 | def append(vec: FingerTreeSeq[String], n: Int): Int = {
27 | var v = vec
28 | var i = 0
29 | while (i < n) {
30 | v = vec :+ ref
31 | i += 1
32 | }
33 | v.length
34 | }
35 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/fingertree/FingerTreeApplyBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.fingertree
2 |
3 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.ApplyBenchmarks
4 | import scala.collection.immutable.vectorutils.VectorGeneratorType
5 |
6 |
7 | abstract class FingerTreeAbstractApplyBenchmark[A] extends ApplyBenchmarks[A] with FingerTreeBenchmark[A]
8 |
9 | class FingerTreeApplyIntBenchmark extends FingerTreeAbstractApplyBenchmark[Int] with VectorGeneratorType.IntGenerator
10 |
11 | class FingerTreeApplyStringBenchmark extends FingerTreeAbstractApplyBenchmark[String] with VectorGeneratorType.StringGenerator
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/fingertree/FingerTreeBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.fingertree
2 |
3 | import org.scalameter.Gen
4 |
5 | import scala.collection.immutable.fingertree._
6 | import scala.collection.immutable.vectorbenchmarks.BaseVectorBenchmark
7 | import scala.collection.immutable.vectorutils.BaseVectorGenerator
8 | import scala.collection.immutable.redblack._
9 |
10 | trait FingerTreeBenchmark[A] extends BaseVectorBenchmark[A] with FingerTreeSeqGenerator[A] {
11 |
12 | override def generateVectors(from: Int, to: Int, by: Int, sizesName: String): Gen[FingerTreeSeq[A]] =
13 | for {
14 | size <- sizes(from, to, by, sizesName)
15 | } yield tabulatedVector(size)
16 |
17 |
18 | def generateVectors2(from: Int, to: Int, by: Int): Gen[(Vec, Vec)] = {
19 | for {
20 | size1 <- sizes(from, to, by, "size1")
21 | size2 <- sizes(from, to, by, "size2")
22 | } yield (tabulatedVector(size1), tabulatedVector(size2))
23 | }
24 |
25 | }
26 |
27 | trait FingerTreeSeqGenerator[A] extends BaseVectorGenerator[A] {
28 | override final type Vec = FingerTreeSeq[A]
29 |
30 | final def vectorClassName: String = "FingerTreeSeq"
31 |
32 |
33 | override final def newBuilder() = FingerTreeSeq.newBuilder[A]
34 |
35 | override final def tabulatedVector(n: Int): Vec =
36 | FingerTreeSeq.tabulate(n)(element)
37 |
38 | override final def rangedVector(start: Int, end: Int): Vec =
39 | FingerTreeSeq.range(start, end) map element
40 |
41 | override final def emptyVector: Vec = FingerTreeSeq.empty[A]
42 |
43 | override def iterator(vec: Vec, start: Int, end: Int) = {
44 | vec.take(end).drop(start).iterator
45 | }
46 |
47 | override def plus(vec: Vec, elem: A): Vec = vec :+ elem
48 |
49 | override def plus(elem: A, vec: Vec): Vec = elem +: vec
50 |
51 | override final def plusPlus(vec1: Vec, vec2: Vec): Vec = vec1 ++ vec2
52 |
53 | override final def take(vec: Vec, n: Int): Vec = vec.take(n)
54 |
55 | override final def drop(vec: Vec, n: Int): Vec = vec.drop(n)
56 | }
57 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/fingertree/FingerTreeBuilderBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.fingertree
2 |
3 | import scala.collection.immutable.fingertree._
4 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.BuilderBenchmarks
5 | import scala.collection.immutable.vectorutils.VectorGeneratorType
6 |
7 | abstract class FingerTreeSeqAbstractBuilderBenchmark[A] extends BuilderBenchmarks[A] with FingerTreeBenchmark[A] {
8 | def buildVector(n: Int): Int = {
9 | var i = 0
10 | var b = FingerTreeSeq.newBuilder[A]
11 | val e = element(0)
12 | while (i < n) {
13 | b += e
14 | i += 1
15 |
16 | }
17 | b.result().length
18 | }
19 | }
20 |
21 | class FingerTreeSeqBuilderIntBenchmark extends FingerTreeSeqAbstractBuilderBenchmark[Int] with VectorGeneratorType.IntGenerator
22 |
23 | class FingerTreeSeqBuilderStringBenchmark extends FingerTreeSeqAbstractBuilderBenchmark[String] with VectorGeneratorType.StringGenerator
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/fingertree/FingerTreeConcatenationBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.fingertree
2 |
3 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.ConcatenationBenchmarks
4 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.Concatenation2Benchmarks
5 | import scala.collection.immutable.vectorutils.VectorGeneratorType
6 |
7 | abstract class FingerTreeAbstractConcatenationBenchmark[A] extends ConcatenationBenchmarks[A] with FingerTreeBenchmark[A]
8 |
9 | class FingerTreeConcatenationIntBenchmark extends FingerTreeAbstractConcatenationBenchmark[Int] with VectorGeneratorType.IntGenerator
10 |
11 | class FingerTreeConcatenationStringBenchmark extends FingerTreeAbstractConcatenationBenchmark[String] with VectorGeneratorType.StringGenerator
12 |
13 |
14 | abstract class FingerTreeAbstractConcatenation2Benchmark[A] extends Concatenation2Benchmarks[A] with FingerTreeBenchmark[A]
15 |
16 | class FingerTreeConcatenation2IntBenchmark extends FingerTreeAbstractConcatenation2Benchmark[Int] with VectorGeneratorType.IntGenerator
17 |
18 | class FingerTreeConcatenation2StringBenchmark extends FingerTreeAbstractConcatenation2Benchmark[String] with VectorGeneratorType.StringGenerator
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/fingertree/FingerTreeIterationBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.fingertree
2 |
3 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.IterationBenchmarks
4 | import scala.collection.immutable.vectorutils.VectorGeneratorType
5 |
6 | abstract class FingerTreeAbstractIterationBenchmark[A] extends IterationBenchmarks[A] with FingerTreeBenchmark[A]
7 |
8 | class FingerTreeIterationIntBenchmark extends FingerTreeAbstractIterationBenchmark[Int] with VectorGeneratorType.IntGenerator
9 |
10 | class FingerTreeIterationStringBenchmark extends FingerTreeAbstractIterationBenchmark[String] with VectorGeneratorType.StringGenerator
11 |
12 |
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/fingertree/FingerTreeMemoryAllocation.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.fingertree
2 |
3 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.MemoryAllocation
4 | import scala.collection.immutable.vectorutils.VectorGeneratorType
5 |
6 |
7 | abstract class FingerTreeAbstractMemoryAllocation[A] extends MemoryAllocation[A] with FingerTreeBenchmark[A]
8 |
9 | class FingerTreeIntMemoryAllocation extends FingerTreeAbstractMemoryAllocation[Int] with VectorGeneratorType.IntGenerator
10 |
11 | class FingerTreeStringMemoryAllocation extends FingerTreeAbstractMemoryAllocation[String] with VectorGeneratorType.StringGenerator
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/fingertree/FingerTreePrependBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.fingertree
2 |
3 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.PrependBenchmarks
4 | import scala.collection.immutable.vectorutils._
5 | import scala.collection.immutable.fingertree.FingerTreeSeq
6 |
7 | abstract class FingerTreeAbstractPrependBenchmark[A] extends PrependBenchmarks[A] with FingerTreeBenchmark[A]
8 |
9 | class FingerTreePrependIntBenchmark extends FingerTreeAbstractPrependBenchmark[Int] with VectorGeneratorType.IntGenerator {
10 |
11 | def prepend(vec: FingerTreeSeq[Int], n: Int, times: Int): Int = {
12 | var i = 0
13 | var v: FingerTreeSeq[Int] = vec
14 | var sum = 0
15 | while (i < times) {
16 | v = vec
17 | var j = 0
18 | while (j < n) {
19 | v = 0 +: vec
20 | j += 1
21 | }
22 | sum += v.length
23 | i += 1
24 | }
25 | sum
26 | }
27 |
28 | }
29 |
30 | class FingerTreePrependStringBenchmark extends FingerTreeAbstractPrependBenchmark[String] with VectorGeneratorType.StringGenerator {
31 | val ref = ""
32 |
33 | def prepend(vec: FingerTreeSeq[String], n: Int, times: Int): Int = {
34 | var i = 0
35 | var v: FingerTreeSeq[String] = null
36 | var sum = 0
37 | while (i < times) {
38 | v = vec
39 | var j = 0
40 | while (j < n) {
41 | v = ref +: vec
42 | j += 1
43 | }
44 | sum += v.length
45 | i += 1
46 | }
47 | sum
48 | }
49 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/fingertree/FingerTreeSplitBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.fingertree
2 |
3 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.SplitBenchmarks
4 | import scala.collection.immutable.vectorutils.VectorGeneratorType
5 |
6 |
7 | abstract class FingerTreeAbstractSplitBenchmark[A] extends SplitBenchmarks[A] with FingerTreeBenchmark[A]
8 |
9 | class FingerTreeSplitIntBenchmark extends FingerTreeAbstractSplitBenchmark[Int] with VectorGeneratorType.IntGenerator
10 |
11 | class FingerTreeSplitStringBenchmark extends FingerTreeAbstractSplitBenchmark[String] with VectorGeneratorType.StringGenerator
12 |
13 |
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/fingertree/FingerTreeUpdateBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.fingertree
2 |
3 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.UpdateBenchmarks
4 | import scala.collection.immutable.vectorutils.VectorGeneratorType
5 |
6 |
7 | abstract class FingerTreeAbstractUpdateBenchmark[A] extends UpdateBenchmarks[A] with FingerTreeBenchmark[A]
8 |
9 | class FingerTreeUpdateIntBenchmark extends FingerTreeAbstractUpdateBenchmark[Int] with VectorGeneratorType.IntGenerator
10 |
11 | class FingerTreeUpdateStringBenchmark extends FingerTreeAbstractUpdateBenchmark[String] with VectorGeneratorType.StringGenerator
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/genericbenchmarks/AppendBenchmarks.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.genericbenchmarks
2 |
3 | import org.scalameter.{Key, PerformanceTest}
4 |
5 | import scala.collection.immutable.vectorbenchmarks.BaseVectorBenchmark
6 |
7 |
8 | abstract class AppendBenchmarks[A] extends BaseVectorBenchmark[A] {
9 | self: PerformanceTest =>
10 |
11 | def append(vec: Vec, n: Int): Int
12 |
13 | performanceOfVectors { height =>
14 | val (from, to, by) = fromToBy(height)
15 |
16 | var sideeffect = 0
17 |
18 | measure method "append" in {
19 | for (elems <- Seq(256)) {
20 | val warmups = 2000
21 | performance of s"append $elems elements" config(
22 | Key.exec.minWarmupRuns -> warmups,
23 | Key.exec.maxWarmupRuns -> warmups
24 | ) in {
25 | performance of s"Height $height" in {
26 | using(generateVectors(from, to, by)) curve vectorName setUp { x: Vec => System.gc()} in { vec =>
27 | sideeffect = append(vec, elems)
28 | }
29 | }
30 | }
31 | }
32 | }
33 |
34 | }
35 |
36 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/genericbenchmarks/ApplyBenchmarks.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.genericbenchmarks
2 |
3 | import org.scalameter.Key
4 |
5 | import scala.collection.immutable.vectorbenchmarks.BaseVectorBenchmark
6 |
7 | abstract class ApplyBenchmarks[A] extends BaseVectorBenchmark[A] {
8 |
9 | performanceOfVectors { height =>
10 | val (from, to, by) = fromToBy(height)
11 |
12 | var sideeffect = 0
13 |
14 | measure method "apply" config(
15 | Key.exec.minWarmupRuns -> 2000,
16 | Key.exec.maxWarmupRuns -> 3000) in {
17 |
18 | performance of "10k iteration" in {
19 | performance of s"Height $height" in {
20 | using(generateVectors(from, to, by)) curve vectorName in { vec =>
21 | var i = 0
22 | var sum = vec(0)
23 | val len = vec.length
24 | val until = 10000
25 | while (i < until) {
26 | sum = vec.apply(i % len)
27 | i += 1
28 | }
29 | sideeffect = sum.hashCode()
30 | }
31 | }
32 | }
33 |
34 | // performance of "10k reverse iteration" in {
35 | // performance of s"Height $height" in {
36 | // using(generateVectors(from, to, by)) curve vectorName in { vec =>
37 | // var i = 10000
38 | // var sum = vec(0)
39 | // val len = vec.length
40 | // while (i > 0) {
41 | // i -= 1
42 | // sum = vec.apply(i % len)
43 | // }
44 | // sideeffect = sum.hashCode()
45 | // }
46 | // }
47 | // }
48 |
49 | def benchmarkFunctionPseudoRandom[Vec <: IndexedSeq[A]](vec: Vec, seed: Int) = {
50 | val rnd = new scala.util.Random(seed)
51 | var i = 0
52 | var sum = vec(0)
53 | val len = vec.length
54 | while (i < 10000) {
55 | sum = vec.apply(rnd.nextInt(len))
56 | i += 1
57 | }
58 | sideeffect = sum.hashCode()
59 | }
60 |
61 | performance of "10k pseudo-random indices (seed=42)" in {
62 | performance of s"Height $height" in {
63 | using(generateVectors(from, to, by)) curve vectorName in (benchmarkFunctionPseudoRandom(_, 42))
64 | }
65 | }
66 |
67 | // performance of "10k pseudo-random indices (seed=274181)" in {
68 | // performance of s"Height $height" in {
69 | // using(generateVectors(from, to, by)) curve vectorName in (benchmarkFunctionPseudoRandom(_, 274181))
70 | // }
71 | // }
72 | //
73 | // performance of "10k pseudo-random indices (seed=53426)" in {
74 | // performance of s"Height $height" in {
75 | // using(generateVectors(from, to, by)) curve vectorName in (benchmarkFunctionPseudoRandom(_, 53426))
76 | // }
77 | // }
78 | }
79 | }
80 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/genericbenchmarks/BuilderBenchmarks.scala:
--------------------------------------------------------------------------------
1 |
2 | package scala.collection.immutable.vectorbenchmarks.genericbenchmarks
3 |
4 | import org.scalameter.Key
5 |
6 | import scala.collection.immutable.vectorbenchmarks.BaseVectorBenchmark
7 |
8 | abstract class BuilderBenchmarks[A] extends BaseVectorBenchmark[A] {
9 |
10 | // override def maxHeight: Int = 4
11 |
12 | def buildVector(n: Int): Int
13 |
14 | performanceOfVectors { height =>
15 | val (from, to, by) = fromToBy(height)
16 |
17 | var sideeffect = 0
18 |
19 | val warmups = if (height <= 2) 2000 else if (height == 3) 200 else 100
20 | measure method "builder" config(
21 | Key.exec.minWarmupRuns -> warmups,
22 | Key.exec.maxWarmupRuns -> warmups
23 | ) in {
24 | performance of s"build vectors of n elements" in {
25 |
26 | performance of s"Height $height" in {
27 | using(sizes(from, to, by, "sizes")) setUp { size => System.gc()} curve vectorName in { n =>
28 | sideeffect = buildVector(n)
29 | }
30 | }
31 | }
32 | }
33 | }
34 |
35 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/genericbenchmarks/Concatenation2Benchmarks.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.genericbenchmarks
2 |
3 | import org.scalameter.{Gen, Key}
4 |
5 | import scala.collection.immutable.vectorbenchmarks.BaseVectorBenchmark
6 |
7 | abstract class Concatenation2Benchmarks[A] extends BaseVectorBenchmark[A] {
8 | // Used in immutable.vector to bound the sizes
9 | def to(n: Int): Int = n
10 |
11 | performanceOfVectors { height =>
12 | // To avoid benchmarking vector concatenation on big immutable.Vector (too slow)
13 | val (from, to_, by) = fromToBy(height)
14 |
15 | var sideeffect = 0
16 |
17 | val warmups = 4000
18 |
19 | performance of "concatenation2" config(
20 | Key.exec.minWarmupRuns -> warmups,
21 | Key.exec.maxWarmupRuns -> 2 * warmups
22 | ) in {
23 |
24 | // performance of s"vectorLHS ++ vectorRHS fixed sum" in {
25 | // performance of s"Height $height" in {
26 | // using(generateVectorsFixedSum(32*32*32)) curve vectorName setUp { x: (Vec, Vec) => System.gc()} in { vecs =>
27 | // val v = plusPlus(vecs._1, vecs._2)
28 | // sideeffect = v.length
29 | // }
30 | // }
31 | // }
32 |
33 | performance of s"vectorLHS ++ vectorRHS fixed LHS" in {
34 | performance of s"Height $height" in {
35 | using(generateVectorsFixedLHS(32*32*16+1, from, to_, by)) curve vectorName setUp { x: (Vec, Vec) => System.gc()} in { vecs =>
36 | val v = plusPlus(vecs._1, vecs._2)
37 | sideeffect = v.length
38 | }
39 | }
40 | }
41 |
42 | performance of s"vectorLHS ++ vectorRHS fixed RHS" in {
43 | performance of s"Height $height" in {
44 | using(generateVectorsFixedRHS(32*32*16+1, from, to_, by)) curve vectorName setUp { x: (Vec, Vec) => System.gc()} in { vecs =>
45 | val v = plusPlus(vecs._1, vecs._2)
46 | sideeffect = v.length
47 | }
48 | }
49 | }
50 | }
51 | }
52 |
53 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/genericbenchmarks/ConcatenationBenchmarks.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.genericbenchmarks
2 |
3 | import org.scalameter.{Gen, Key}
4 |
5 | import scala.collection.immutable.vectorbenchmarks.BaseVectorBenchmark
6 |
7 | abstract class ConcatenationBenchmarks[A] extends BaseVectorBenchmark[A] {
8 | // Used in immutable.vector to bound the sizes
9 | def to(n: Int): Int = n
10 |
11 | override def minHeight = 3
12 |
13 | override def maxHeight = 3
14 |
15 | override def points = 16
16 |
17 | def generateVectors2(from: Int, to: Int, by: Int): Gen[(Vec, Vec)]
18 |
19 | performanceOfVectors { height =>
20 | // To avoid benchmarking vector concatenation on big immutable.Vector (too slow)
21 | val (from, to_, by) = fromToBy(height)
22 |
23 | var sideeffect = 0
24 |
25 | val warmups = 2500
26 |
27 | performance of "concatenation" config(
28 | Key.exec.minWarmupRuns -> warmups,
29 | Key.exec.maxWarmupRuns -> 2 * warmups
30 | ) in {
31 | performance of s"vector1 ++ vector2" in {
32 | performance of s"Height $height" in {
33 | using(generateVectors2(from, to_, by)) curve vectorName setUp { x: (Vec, Vec) => System.gc()} in { vecs =>
34 | val v = plusPlus(vecs._1, vecs._2)
35 | sideeffect = v.length
36 | }
37 | }
38 | }
39 |
40 | }
41 | }
42 |
43 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/genericbenchmarks/IterationBenchmarks.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.genericbenchmarks
2 |
3 | import org.scalameter.Key
4 |
5 | import scala.collection.immutable.vectorbenchmarks.BaseVectorBenchmark
6 |
7 |
8 | abstract class IterationBenchmarks[A] extends BaseVectorBenchmark[A] {
9 |
10 | // override val maxHeight: Int = 3
11 |
12 | performanceOfVectors { height =>
13 | val (from, to, by) = fromToBy(height)
14 |
15 | var sideeffect = 0
16 |
17 | val warmups = if (height == 1) 500 else if (height == 2) 300 else if (height == 3) 200 else 75
18 | performance of "iteration" config(
19 | Key.exec.minWarmupRuns -> warmups,
20 | Key.exec.minWarmupRuns -> warmups
21 | ) in {
22 |
23 | performance of "iterator: iterate through all elements" in {
24 | performance of s"Height $height" in {
25 | using(generateVectors(from, to, by)) curve vectorName in { vec =>
26 | val it = vec.iterator
27 | var seff = 0
28 | while (it.hasNext) {
29 | seff = it.next().hashCode()
30 | }
31 | sideeffect = seff
32 | }
33 | }
34 | }
35 |
36 | performance of "reverseIterator: iterate through all elements" in {
37 | performance of s"Height $height" in {
38 | using(generateVectors(from, to, by)) curve vectorName in { vec =>
39 | val it = vec.reverseIterator
40 | var seff = 0
41 | while (it.hasNext) {
42 | seff = it.next().hashCode()
43 | }
44 | sideeffect = seff
45 | }
46 | }
47 | }
48 | }
49 | }
50 |
51 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/genericbenchmarks/MemoryAllocation.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.genericbenchmarks
2 |
3 | import org.scalameter._
4 |
5 | import scala.collection.immutable.vectorbenchmarks.BaseVectorBenchmark
6 |
7 |
8 | abstract class MemoryAllocation[A] extends BaseVectorBenchmark[A] {
9 |
10 | override def measurer = new Executor.Measurer.MemoryFootprint
11 |
12 | performanceOfVectors { height =>
13 |
14 | val (from, to, by) = fromToBy(height)
15 |
16 | var sideeffect = 0
17 | performance of "MemoryFootprint (KB not ms)" in {
18 | performance of s"Height $height" in {
19 | using(generateVectors(from, to, by)) curve vectorName in { vec => vec}
20 | }
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/genericbenchmarks/ParSupport.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.genericbenchmarks
2 |
3 | import scala.collection.parallel.ForkJoinTaskSupport
4 |
5 | object ParSupport {
6 |
7 | lazy val pool1 = new scala.concurrent.forkjoin.ForkJoinPool(1)
8 | lazy val pool2 = new scala.concurrent.forkjoin.ForkJoinPool(2)
9 | lazy val pool4 = new scala.concurrent.forkjoin.ForkJoinPool(4)
10 | lazy val pool8 = new scala.concurrent.forkjoin.ForkJoinPool(8)
11 | lazy val pool16 = new scala.concurrent.forkjoin.ForkJoinPool(16)
12 | lazy val pool32 = new scala.concurrent.forkjoin.ForkJoinPool(32)
13 | lazy val pool64 = new scala.concurrent.forkjoin.ForkJoinPool(64)
14 |
15 | def getTaskSupport(n: Int) = n match {
16 | case 1 => new ForkJoinTaskSupport(pool1)
17 | case 2 => new ForkJoinTaskSupport(pool2)
18 | case 4 => new ForkJoinTaskSupport(pool4)
19 | case 8 => new ForkJoinTaskSupport(pool8)
20 | case 16 => new ForkJoinTaskSupport(pool16)
21 | case 32 => new ForkJoinTaskSupport(pool32)
22 | case 64 => new ForkJoinTaskSupport(pool64)
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/genericbenchmarks/PrependBenchmarks.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.genericbenchmarks
2 |
3 | import org.scalameter.{Key, PerformanceTest}
4 |
5 | import scala.collection.immutable.vectorbenchmarks.BaseVectorBenchmark
6 |
7 |
8 | abstract class PrependBenchmarks[A] extends BaseVectorBenchmark[A] {
9 | self: PerformanceTest =>
10 |
11 | def prepend(vec: Vec, n: Int, times: Int): Int
12 |
13 | performanceOfVectors { height =>
14 | val (from, to, by) = fromToBy(height)
15 |
16 | var sideeffect = 0
17 |
18 | measure method "prepend" in {
19 | val elems = 256
20 | val warmups = 2000
21 | performance of s"prepend $elems elements" config(
22 | Key.exec.minWarmupRuns -> warmups,
23 | Key.exec.maxWarmupRuns -> warmups
24 | ) in {
25 | performance of s"Height $height" in {
26 | using(generateVectors(from, to, by)) curve vectorName setUp { x: Vec => System.gc()} in { vec =>
27 | sideeffect = prepend(vec, elems, 1)
28 | }
29 | }
30 | }
31 | }
32 |
33 | }
34 |
35 |
36 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/genericbenchmarks/SplitBenchmarks.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.genericbenchmarks
2 |
3 | import org.scalameter.Key
4 |
5 |
6 | import scala.collection.immutable.vectorbenchmarks.BaseVectorBenchmark
7 |
8 | abstract class SplitBenchmarks[A] extends BaseVectorBenchmark[A] {
9 |
10 | performanceOfVectors { height =>
11 | val (from, to, by) = fromToBy(height)
12 |
13 | var sideeffect = 0
14 |
15 | measure method "take" config(
16 | Key.exec.minWarmupRuns -> 500,
17 | Key.exec.maxWarmupRuns -> 1000) in {
18 |
19 | performance of s"take half" in {
20 | performance of s"Height $height" in {
21 | using(generateVectors(from, to, by)) curve vectorName setUp { x: Vec => System.gc()} in { vec =>
22 | sideeffect = take(vec, vec.length / 2).length
23 | }
24 | }
25 | }
26 |
27 | performance of s"take quarter" in {
28 | performance of s"Height $height" in {
29 | using(generateVectors(from, to, by)) curve vectorName setUp { x: Vec => System.gc()} in { vec =>
30 | sideeffect = take(vec, vec.length / 4).length
31 | }
32 | }
33 | }
34 |
35 | performance of s"take third" in {
36 | performance of s"Height $height" in {
37 | using(generateVectors(from, to, by)) curve vectorName setUp { x: Vec => System.gc()} in { vec =>
38 | sideeffect = take(vec, vec.length / 3).length
39 | }
40 | }
41 | }
42 |
43 | performance of s"take seventh" in {
44 | performance of s"Height $height" in {
45 | using(generateVectors(from, to, by)) curve vectorName setUp { x: Vec => System.gc()} in { vec =>
46 | sideeffect = take(vec, vec.length / 7).length
47 | }
48 | }
49 | }
50 |
51 | }
52 |
53 |
54 | measure method "drop" config(
55 | Key.exec.minWarmupRuns -> 500,
56 | Key.exec.maxWarmupRuns -> 1000) in {
57 |
58 | performance of s"drop half" in {
59 | performance of s"Height $height" in {
60 | using(generateVectors(from, to, by)) curve vectorName setUp { x: Vec => System.gc()} in { vec =>
61 | sideeffect = drop(vec, vec.length / 2).length
62 | }
63 | }
64 | }
65 |
66 | performance of s"drop quarter" in {
67 | performance of s"Height $height" in {
68 | using(generateVectors(from, to, by)) curve vectorName setUp { x: Vec => System.gc()} in { vec =>
69 | sideeffect = drop(vec, vec.length / 4).length
70 | }
71 | }
72 | }
73 |
74 | performance of s"drop third" in {
75 | performance of s"Height $height" in {
76 | using(generateVectors(from, to, by)) curve vectorName setUp { x: Vec => System.gc()} in { vec =>
77 | sideeffect = drop(vec, vec.length / 3).length
78 | }
79 | }
80 | }
81 |
82 | performance of s"drop seventh" in {
83 | performance of s"Height $height" in {
84 | using(generateVectors(from, to, by)) curve vectorName setUp { x: Vec => System.gc()} in { vec =>
85 | sideeffect = drop(vec, vec.length / 7).length
86 | }
87 | }
88 | }
89 | }
90 | }
91 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/genericbenchmarks/UpdateBenchmarks.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.genericbenchmarks
2 |
3 | import org.scalameter.Key
4 |
5 | import scala.collection.immutable.vectorbenchmarks.BaseVectorBenchmark
6 |
7 | abstract class UpdateBenchmarks[A] extends BaseVectorBenchmark[A] {
8 | def to(n: Int): Int = n
9 |
10 | performanceOfVectors { height =>
11 | val (from, _to, by) = fromToBy(height)
12 |
13 | var sideeffect = 0
14 |
15 | measure method "upadte" config(
16 | Key.exec.minWarmupRuns -> 1500,
17 | Key.exec.maxWarmupRuns -> 2000) in {
18 |
19 | performance of "10k iteration" in {
20 | performance of s"Height $height" in {
21 | using(generateVectors(from, to(_to), by)) curve vectorName in { vec =>
22 | var i = 0
23 | var v: IndexedSeq[A] = vec
24 | val elem = vec(0)
25 | val len = vec.length
26 | val until = 10000
27 | while (i < until) {
28 | v = v.updated(i % len, elem)
29 | i += 1
30 | }
31 | sideeffect = v.length
32 | }
33 | }
34 | }
35 |
36 | // performance of "10k reverse iteration" in {
37 | // performance of s"Height $height" in {
38 | // using(generateVectors(from, to(_to), by)) curve vectorName in { vec =>
39 | // var i = 10000
40 | // var v: IndexedSeq[A] = vec
41 | // val elem = vec(0)
42 | // val len = vec.length
43 | // while (i > 0) {
44 | // i -= 1
45 | // v = v.updated(i % len, elem)
46 | // }
47 | // sideeffect = v.length
48 | // }
49 | // }
50 | // }
51 |
52 | def benchmarkFunctionPseudoRandom[Vec <: IndexedSeq[A]](vec: Vec, seed: Int) = {
53 | val rnd = new scala.util.Random(seed)
54 | var i = 0
55 | var v: IndexedSeq[A] = vec
56 | val elem = vec(0)
57 | val len = vec.length
58 | while (i < 10000) {
59 | v = v.updated(rnd.nextInt(len), elem)
60 | i += 1
61 | }
62 | sideeffect = v.length
63 | }
64 |
65 | performance of "10k pseudo-random indices (seed=42)" in {
66 | performance of s"Height $height" in {
67 | using(generateVectors(from, to(_to), by)) curve vectorName in (benchmarkFunctionPseudoRandom(_, 42))
68 | }
69 | }
70 |
71 | // performance of "10k pseudo-random indices (seed=274181)" in {
72 | // performance of s"Height $height" in {
73 | // using(generateVectors(from, to, by)) curve vectorName in (benchmarkFunctionPseudoRandom(_, 274181))
74 | // }
75 | // }
76 | //
77 | // performance of "10k pseudo-random indices (seed=53426)" in {
78 | // performance of s"Height $height" in {
79 | // using(generateVectors(from, to, by)) curve vectorName in (benchmarkFunctionPseudoRandom(_, 53426))
80 | // }
81 | // }
82 | }
83 | }
84 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/redblack/RedBlackSeqAppendBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.redblack
2 |
3 | import scala.collection.immutable.redblack.RedBlackSeq
4 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.AppendBenchmarks
5 | import scala.collection.immutable.vectorutils.VectorGeneratorType
6 |
7 | abstract class RedBlackSeqAbstractAppendBenchmark[A] extends AppendBenchmarks[A] with RedBlackSeqBenchmark[A]
8 |
9 | class RedBlackSeqAppendIntBenchmark extends RedBlackSeqAbstractAppendBenchmark[Int] with VectorGeneratorType.IntGenerator {
10 |
11 | def append(vec: RedBlackSeq[Int], n: Int): Int = {
12 | var v = vec
13 | var i = 0
14 | while (i < n) {
15 | v = vec :+ 0
16 | i += 1
17 | }
18 | v.length
19 | }
20 |
21 | }
22 |
23 | class RedBlackSeqAppendStringBenchmark extends RedBlackSeqAbstractAppendBenchmark[String] with VectorGeneratorType.StringGenerator {
24 | val ref = ""
25 |
26 | def append(vec: RedBlackSeq[String], n: Int): Int = {
27 | var v = vec
28 | var i = 0
29 | while (i < n) {
30 | v = vec :+ ref
31 | i += 1
32 | }
33 | v.length
34 | }
35 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/redblack/RedBlackSeqApplyBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.redblack
2 |
3 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.ApplyBenchmarks
4 | import scala.collection.immutable.vectorutils.VectorGeneratorType
5 |
6 |
7 | abstract class RedBlackSeqAbstractApplyBenchmark[A] extends ApplyBenchmarks[A] with RedBlackSeqBenchmark[A]
8 |
9 | class RedBlackSeqApplyIntBenchmark extends RedBlackSeqAbstractApplyBenchmark[Int] with VectorGeneratorType.IntGenerator
10 |
11 | class RedBlackSeqApplyStringBenchmark extends RedBlackSeqAbstractApplyBenchmark[String] with VectorGeneratorType.StringGenerator
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/redblack/RedBlackSeqBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.redblack
2 |
3 | import org.scalameter.Gen
4 |
5 | import scala.collection.immutable.redblack._
6 | import scala.collection.immutable.vectorbenchmarks.BaseVectorBenchmark
7 | import scala.collection.immutable.vectorutils._
8 |
9 | trait RedBlackSeqBenchmark[A] extends BaseVectorBenchmark[A] with RedBlackSeqGenerator[A] {
10 |
11 | override def generateVectors(from: Int, to: Int, by: Int, sizesName: String): Gen[RedBlackSeq[A]] =
12 | for {
13 | size <- sizes(from, to, by, sizesName)
14 | } yield tabulatedVector(size)
15 |
16 |
17 | def generateVectors2(from: Int, to: Int, by: Int): Gen[(Vec, Vec)] = {
18 | for {
19 | size1 <- sizes(from, to, by, "size1")
20 | size2 <- sizes(from, to, by, "size2")
21 | } yield (tabulatedVector(size1), tabulatedVector(size2))
22 | }
23 |
24 | }
25 |
26 | trait RedBlackSeqGenerator[A] extends BaseVectorGenerator[A] {
27 | override final type Vec = RedBlackSeq[A]
28 |
29 | final def vectorClassName: String = "RedBlackSeq"
30 |
31 |
32 | override final def newBuilder() = RedBlackSeq.newBuilder[A]
33 |
34 | override final def tabulatedVector(n: Int): Vec =
35 | RedBlackSeq.tabulate(n)(element)
36 |
37 | override final def rangedVector(start: Int, end: Int): Vec =
38 | RedBlackSeq.range(start, end) map element
39 |
40 | override final def emptyVector: Vec = RedBlackSeq.empty[A]
41 |
42 | override def iterator(vec: Vec, start: Int, end: Int) = {
43 | vec.take(end).drop(start).iterator
44 | }
45 |
46 | override def plus(vec: Vec, elem: A): Vec = vec :+ elem
47 |
48 | override def plus(elem: A, vec: Vec): Vec = elem +: vec
49 |
50 | override final def plusPlus(vec1: Vec, vec2: Vec): Vec = vec1 ++ vec2
51 |
52 | override final def take(vec: Vec, n: Int): Vec = vec.take(n)
53 |
54 | override final def drop(vec: Vec, n: Int): Vec = vec.drop(n)
55 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/redblack/RedBlackSeqBuilderBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.redblack
2 |
3 | import scala.collection.immutable.redblack._
4 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.BuilderBenchmarks
5 | import scala.collection.immutable.vectorutils.VectorGeneratorType
6 |
7 | abstract class RedBlackSeqAbstractBuilderBenchmark[A] extends BuilderBenchmarks[A] with RedBlackSeqBenchmark[A] {
8 | def buildVector(n: Int): Int = {
9 | var i = 0
10 | var b = RedBlackSeq.newBuilder[A]
11 | val e = element(0)
12 | while (i < n) {
13 | b += e
14 | i += 1
15 |
16 | }
17 | b.result().length
18 | }
19 | }
20 |
21 | class RedBlackSeqBuilderIntBenchmark extends RedBlackSeqAbstractBuilderBenchmark[Int] with VectorGeneratorType.IntGenerator
22 |
23 | class RedBlackSeqBuilderStringBenchmark extends RedBlackSeqAbstractBuilderBenchmark[String] with VectorGeneratorType.StringGenerator
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/redblack/RedBlackSeqConcatenationBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.redblack
2 |
3 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.ConcatenationBenchmarks
4 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.Concatenation2Benchmarks
5 | import scala.collection.immutable.vectorutils.VectorGeneratorType
6 |
7 | abstract class RedBlackSeqAbstractConcatenationBenchmark[A] extends ConcatenationBenchmarks[A] with RedBlackSeqBenchmark[A] {
8 | override def points = super.points / 2
9 | }
10 |
11 | class RedBlackSeqConcatenationIntBenchmark extends RedBlackSeqAbstractConcatenationBenchmark[Int] with VectorGeneratorType.IntGenerator
12 |
13 | class RedBlackSeqConcatenationStringBenchmark extends RedBlackSeqAbstractConcatenationBenchmark[String] with VectorGeneratorType.StringGenerator
14 |
15 |
16 | abstract class RedBlackSeqAbstractConcatenation2Benchmark[A] extends Concatenation2Benchmarks[A] with RedBlackSeqBenchmark[A]
17 |
18 | class RedBlackSeqConcatenation2IntBenchmark extends RedBlackSeqAbstractConcatenation2Benchmark[Int] with VectorGeneratorType.IntGenerator
19 |
20 | class RedBlackSeqConcatenation2StringBenchmark extends RedBlackSeqAbstractConcatenation2Benchmark[String] with VectorGeneratorType.StringGenerator
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/redblack/RedBlackSeqIterationBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.redblack
2 |
3 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.IterationBenchmarks
4 | import scala.collection.immutable.vectorutils.VectorGeneratorType
5 |
6 | abstract class RedBlackSeqAbstractIterationBenchmark[A] extends IterationBenchmarks[A] with RedBlackSeqBenchmark[A]
7 |
8 | class RedBlackSeqIterationIntBenchmark extends RedBlackSeqAbstractIterationBenchmark[Int] with VectorGeneratorType.IntGenerator
9 |
10 | class RedBlackSeqIterationStringBenchmark extends RedBlackSeqAbstractIterationBenchmark[String] with VectorGeneratorType.StringGenerator
11 |
12 |
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/redblack/RedBlackSeqMemoryAllocation.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.redblack
2 |
3 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.MemoryAllocation
4 | import scala.collection.immutable.vectorutils.VectorGeneratorType
5 |
6 |
7 | abstract class RedBlackSeqAbstractMemoryAllocation[A] extends MemoryAllocation[A] with RedBlackSeqBenchmark[A]
8 |
9 | class RedBlackSeqIntMemoryAllocation extends RedBlackSeqAbstractMemoryAllocation[Int] with VectorGeneratorType.IntGenerator
10 |
11 | class RedBlackSeqStringMemoryAllocation extends RedBlackSeqAbstractMemoryAllocation[String] with VectorGeneratorType.StringGenerator
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/redblack/RedBlackSeqPrependBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.redblack
2 |
3 | import scala.collection.immutable.redblack.RedBlackSeq
4 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.PrependBenchmarks
5 | import scala.collection.immutable.vectorutils._
6 |
7 | abstract class RedBlackSeqAbstractPrependBenchmark[A] extends PrependBenchmarks[A] with RedBlackSeqBenchmark[A]
8 |
9 | class RedBlackSeqPrependIntBenchmark extends RedBlackSeqAbstractPrependBenchmark[Int] with VectorGeneratorType.IntGenerator {
10 |
11 | def prepend(vec: RedBlackSeq[Int], n: Int, times: Int): Int = {
12 | var i = 0
13 | var v: RedBlackSeq[Int] = vec
14 | var sum = 0
15 | while (i < times) {
16 | v = vec
17 | var j = 0
18 | while (j < n) {
19 | v = 0 +: vec
20 | j += 1
21 | }
22 | sum += v.length
23 | i += 1
24 | }
25 | sum
26 | }
27 |
28 | }
29 |
30 | class RedBlackSeqPrependStringBenchmark extends RedBlackSeqAbstractPrependBenchmark[String] with VectorGeneratorType.StringGenerator {
31 | val ref = ""
32 |
33 | def prepend(vec: RedBlackSeq[String], n: Int, times: Int): Int = {
34 | var i = 0
35 | var v: RedBlackSeq[String] = null
36 | var sum = 0
37 | while (i < times) {
38 | v = vec
39 | var j = 0
40 | while (j < n) {
41 | v = ref +: vec
42 | j += 1
43 | }
44 | sum += v.length
45 | i += 1
46 | }
47 | sum
48 | }
49 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/redblack/RedBlackSeqSplitBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.redblack
2 |
3 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.SplitBenchmarks
4 | import scala.collection.immutable.vectorutils.VectorGeneratorType
5 |
6 |
7 | abstract class RedBlackSeqAbstractSplitBenchmark[A] extends SplitBenchmarks[A] with RedBlackSeqBenchmark[A]
8 |
9 | class RedBlackSeqSplitIntBenchmark extends RedBlackSeqAbstractSplitBenchmark[Int] with VectorGeneratorType.IntGenerator
10 |
11 | class RedBlackSeqSplitStringBenchmark extends RedBlackSeqAbstractSplitBenchmark[String] with VectorGeneratorType.StringGenerator
12 |
13 |
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/redblack/RedBlackSeqUpdateBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.redblack
2 |
3 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.UpdateBenchmarks
4 | import scala.collection.immutable.vectorutils.VectorGeneratorType
5 |
6 |
7 | abstract class RedBlackSeqAbstractUpdateBenchmark[A] extends UpdateBenchmarks[A] with RedBlackSeqBenchmark[A]
8 |
9 | class RedBlackSeqUpdateIntBenchmark extends RedBlackSeqAbstractUpdateBenchmark[Int] with VectorGeneratorType.IntGenerator
10 |
11 | class RedBlackSeqUpdateStringBenchmark extends RedBlackSeqAbstractUpdateBenchmark[String] with VectorGeneratorType.StringGenerator
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/rrbvector/balanced/RRBVectorAbstractBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.rrbvector.balanced
2 |
3 | import org.scalameter.Gen
4 |
5 | import scala.collection.immutable.rrbvector.RRBVector
6 | import scala.collection.immutable.vectorbenchmarks.BaseVectorBenchmark
7 | import scala.collection.immutable.vectorutils.BaseVectorGenerator.RRBVectorGenerator
8 |
9 | trait RRBVectorAbstractBenchmark[A] extends BaseVectorBenchmark[A] with RRBVectorGenerator[A] {
10 | override def generateVectors(from: Int, to: Int, by: Int, sizesName: String) = sizes(from, to, by, sizesName).map(((size) => tabulatedVector(size)));
11 |
12 | def generateVectors2(from: Int, to: Int, by: Int): Gen[(Vec, Vec)] = {
13 | for {
14 | size1 <- sizes(from, to, by, "size1")
15 | size2 <- sizes(from, to, by, "size2")
16 | } yield (tabulatedVector(size1), tabulatedVector(size2))
17 | }
18 |
19 | override def vectorName: String = if (RRBVector.compileAssertions) throw new IllegalStateException("RRBVector.compileAssertions must be false to run benchmarks.") else super.vectorName.+("Balanced")
20 | }
21 |
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/rrbvector/balanced/RRBVectorAbstractPrependBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.rrbvector.balanced
2 |
3 | import scala.collection.immutable.rrbvector.RRBVector
4 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.PrependBenchmarks
5 | import scala.collection.immutable.vectorutils._
6 |
7 |
8 | abstract class RRBVectorAbstractPrependBenchmark[A] extends PrependBenchmarks[A] with RRBVectorAbstractBenchmark[A]
9 |
10 | class RRBVectorPrependIntBenchmark extends RRBVectorAbstractPrependBenchmark[Int] with VectorGeneratorType.IntGenerator {
11 |
12 |
13 | def prepend(vec: RRBVector[Int], n: Int, times: Int): Int = {
14 | var i = 0
15 | var v: RRBVector[Int] = vec
16 | var sum = 0
17 | while (i < times) {
18 | v = vec
19 | var j = 0
20 | while (j < n) {
21 | v = 0 +: vec
22 | j += 1
23 | }
24 | sum += v.length
25 | i += 1
26 | }
27 | sum
28 | }
29 |
30 | }
31 |
32 | class RRBVectorPrependStringBenchmark extends RRBVectorAbstractPrependBenchmark[String] with VectorGeneratorType.StringGenerator {
33 | val ref = ""
34 |
35 | def prepend(vec: RRBVector[String], n: Int, times: Int): Int = {
36 | var i = 0
37 | var v: RRBVector[String] = null
38 | var sum = 0
39 | while (i < times) {
40 | v = vec
41 | var j = 0
42 | while (j < n) {
43 | v = ref +: vec
44 | j += 1
45 | }
46 | sum += v.length
47 | i += 1
48 | }
49 | sum
50 | }
51 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/rrbvector/balanced/RRBVectorAppendBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.rrbvector.balanced
2 |
3 | import scala.collection.immutable.rrbvector.RRBVector
4 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.AppendBenchmarks
5 | import scala.collection.immutable.vectorutils._
6 |
7 |
8 | abstract class RRBVectorAbstractAppendBenchmark[A] extends AppendBenchmarks[A] with RRBVectorAbstractBenchmark[A]
9 |
10 | class RRBVectorAppendIntBenchmark extends RRBVectorAbstractAppendBenchmark[Int] with VectorGeneratorType.IntGenerator {
11 |
12 | def append(vec: RRBVector[Int], n: Int): Int = {
13 | var i = 0
14 | var v = vec
15 | while (i < n) {
16 | v = vec :+ 0
17 | i += 1
18 | }
19 | v.length
20 | }
21 |
22 | }
23 |
24 | class RRBVectorAppendStringBenchmark extends RRBVectorAbstractAppendBenchmark[String] with VectorGeneratorType.StringGenerator {
25 | val ref = ""
26 |
27 | def append(vec: RRBVector[String], n: Int): Int = {
28 | var v = vec
29 | var i = 0
30 | while (i < n) {
31 | v = vec :+ ref
32 | i += 1
33 | }
34 | v.length
35 | }
36 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/rrbvector/balanced/RRBVectorApplyBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.rrbvector.balanced
2 |
3 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.ApplyBenchmarks
4 | import scala.collection.immutable.vectorutils.VectorGeneratorType
5 |
6 |
7 | abstract class RRBVectorAbstractApplyBenchmark[A] extends ApplyBenchmarks[A] with RRBVectorAbstractBenchmark[A]
8 |
9 | class RRBVectorApplyIntBenchmark extends RRBVectorAbstractApplyBenchmark[Int] with VectorGeneratorType.IntGenerator
10 |
11 | class RRBVectorApplyStringBenchmark extends RRBVectorAbstractApplyBenchmark[String] with VectorGeneratorType.StringGenerator
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/rrbvector/balanced/RRBVectorBuilderBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.rrbvector.balanced
2 |
3 | import scala.collection.immutable.rrbvector.RRBVector
4 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.BuilderBenchmarks
5 | import scala.collection.immutable.vectorutils.VectorGeneratorType
6 |
7 | abstract class RRBVectorAbstractBuilderBenchmark[A] extends BuilderBenchmarks[A] with RRBVectorAbstractBenchmark[A] {
8 | def buildVector(n: Int): Int = {
9 | var i = 0
10 | var b = RRBVector.newBuilder[A]
11 | val e = element(0)
12 | while (i < n) {
13 | b += e
14 | i += 1
15 | }
16 | b.result().length
17 | }
18 | }
19 |
20 | class RRBVectorBuilderIntBenchmark extends RRBVectorAbstractBuilderBenchmark[Int] with VectorGeneratorType.IntGenerator
21 |
22 | class RRBVectorBuilderStringBenchmark extends RRBVectorAbstractBuilderBenchmark[String] with VectorGeneratorType.StringGenerator
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/rrbvector/balanced/RRBVectorConcatenationBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.rrbvector.balanced
2 |
3 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.ConcatenationBenchmarks
4 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.Concatenation2Benchmarks
5 | import scala.collection.immutable.vectorutils.VectorGeneratorType
6 |
7 | abstract class RRBVectorAbstractConcatenationBenchmark[A] extends ConcatenationBenchmarks[A] with RRBVectorAbstractBenchmark[A]
8 |
9 | class RRBVectorConcatenationIntBenchmark extends RRBVectorAbstractConcatenationBenchmark[Int] with VectorGeneratorType.IntGenerator
10 |
11 | class RRBVectorConcatenationStringBenchmark extends RRBVectorAbstractConcatenationBenchmark[String] with VectorGeneratorType.StringGenerator
12 |
13 |
14 | abstract class RRBVectorAbstractConcatenation2Benchmark[A] extends Concatenation2Benchmarks[A] with RRBVectorAbstractBenchmark[A]
15 |
16 | class RRBVectorConcatenation2IntBenchmark extends RRBVectorAbstractConcatenation2Benchmark[Int] with VectorGeneratorType.IntGenerator
17 |
18 | class RRBVectorConcatenation2StringBenchmark extends RRBVectorAbstractConcatenation2Benchmark[String] with VectorGeneratorType.StringGenerator
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/rrbvector/balanced/RRBVectorIterationBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.rrbvector.balanced
2 |
3 | import scala.collection.immutable.vectorbenchmarks._
4 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.IterationBenchmarks
5 | import scala.collection.immutable.vectorutils.VectorGeneratorType
6 |
7 | abstract class RRBVectorAbstractIterationBenchmark[A] extends IterationBenchmarks[A] with RRBVectorAbstractBenchmark[A]
8 |
9 | class RRBVectorIterationIntBenchmark extends RRBVectorAbstractIterationBenchmark[Int] with VectorGeneratorType.IntGenerator
10 |
11 | class RRBVectorIterationStringBenchmark extends RRBVectorAbstractIterationBenchmark[String] with VectorGeneratorType.StringGenerator
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/rrbvector/balanced/RRBVectorMemoryAllocation.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.rrbvector.balanced
2 |
3 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.MemoryAllocation
4 | import scala.collection.immutable.vectorutils.VectorGeneratorType
5 |
6 |
7 | abstract class RRBVectorAbstractMemoryAllocation[A] extends MemoryAllocation[A] with RRBVectorAbstractBenchmark[A]
8 |
9 | class RRBVectorIntMemoryAllocation extends RRBVectorAbstractMemoryAllocation[Int] with VectorGeneratorType.IntGenerator
10 |
11 | class RRBVectorStringMemoryAllocation extends RRBVectorAbstractMemoryAllocation[String] with VectorGeneratorType.StringGenerator
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/rrbvector/balanced/RRBVectorParMapBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.rrbvector.balanced
2 |
3 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.ParMapBenchmarks
4 | import scala.collection.immutable.vectorutils.VectorGeneratorType
5 |
6 |
7 | abstract class RRBVectorAbstractParMapBenchmark[A] extends ParMapBenchmarks[A] with RRBVectorAbstractBenchmark[A]
8 |
9 | class RRBVectorParMapIntBenchmark extends RRBVectorAbstractParMapBenchmark[Int] with VectorGeneratorType.IntGenerator
10 |
11 | class RRBVectorParMapStringBenchmark extends RRBVectorAbstractParMapBenchmark[String] with VectorGeneratorType.StringGenerator
12 |
13 |
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/rrbvector/balanced/RRBVectorSplitBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.rrbvector.balanced
2 |
3 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.SplitBenchmarks
4 | import scala.collection.immutable.vectorutils.VectorGeneratorType
5 |
6 |
7 | abstract class RRBVectorAbstractSplitBenchmark[A] extends SplitBenchmarks[A] with RRBVectorAbstractBenchmark[A]
8 |
9 | class RRBVectorSplitIntBenchmark extends RRBVectorAbstractSplitBenchmark[Int] with VectorGeneratorType.IntGenerator
10 |
11 | class RRBVectorSplitStringBenchmark extends RRBVectorAbstractSplitBenchmark[String] with VectorGeneratorType.StringGenerator
12 |
13 |
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/rrbvector/balanced/RRBVectorUpdateBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.rrbvector.balanced
2 |
3 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.UpdateBenchmarks
4 | import scala.collection.immutable.vectorutils.VectorGeneratorType
5 |
6 |
7 | abstract class RRBVectorAbstractUpdateBenchmark[A] extends UpdateBenchmarks[A] with RRBVectorAbstractBenchmark[A]
8 |
9 | class RRBVectorUpdateIntBenchmark extends RRBVectorAbstractUpdateBenchmark[Int] with VectorGeneratorType.IntGenerator
10 |
11 | class RRBVectorUpdateStringBenchmark extends RRBVectorAbstractUpdateBenchmark[String] with VectorGeneratorType.StringGenerator
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/rrbvector/unbalanced1/RRBVectorAbstractBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.rrbvector.unbalanced1
2 |
3 | import org.scalameter.Gen
4 |
5 | import scala.collection.immutable.rrbvector.RRBVector
6 | import scala.collection.immutable.vectorbenchmarks.BaseVectorBenchmark
7 | import scala.collection.immutable.vectorutils.BaseVectorGenerator.RRBVectorGenerator
8 |
9 | trait RRBVectorAbstractBenchmark[A] extends BaseVectorBenchmark[A] with RRBVectorGenerator[A] {
10 | override def minHeight = 3
11 |
12 | override def generateVectors(from: Int, to: Int, by: Int,sizesName:String) = {
13 | sizes(from, to, by, sizesName) map { n =>
14 | rangedVector(0, n / 2) ++ rangedVector(n / 2, n)
15 | }
16 | }
17 |
18 | def generateVectors2(from: Int, to: Int, by: Int): Gen[(Vec, Vec)] = {
19 | for {
20 | size1 <- sizes(from, to, by, "size1")
21 | size2 <- sizes(from, to, by, "size2")
22 | } yield (rangedVector(0, size1 / 2) ++ rangedVector(size1 / 2, size1),rangedVector(0, size2 / 2) ++ rangedVector(size2 / 2, size2))
23 | }
24 |
25 | override def vectorName: String = if (RRBVector.compileAssertions) throw new IllegalStateException("RRBVector.compileAssertions must be false to run benchmarks.") else super.vectorName.+("Unbalanced1")
26 | }
27 |
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/rrbvector/unbalanced1/RRBVectorAbstractPrependBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.rrbvector.unbalanced1
2 |
3 | import scala.collection.immutable.rrbvector.RRBVector
4 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.PrependBenchmarks
5 | import scala.collection.immutable.vectorutils._
6 |
7 |
8 | abstract class RRBVectorAbstractPrependBenchmark[A] extends PrependBenchmarks[A] with RRBVectorAbstractBenchmark[A]
9 |
10 | class RRBVectorPrependIntBenchmark extends RRBVectorAbstractPrependBenchmark[Int] with VectorGeneratorType.IntGenerator {
11 |
12 |
13 | def prepend(vec: RRBVector[Int], n: Int, times: Int): Int = {
14 | var i = 0
15 | var v: RRBVector[Int] = vec
16 | var sum = 0
17 | while (i < times) {
18 | v = vec
19 | var j = 0
20 | while (j < n) {
21 | v = 0 +: vec
22 | j += 1
23 | }
24 | sum += v.length
25 | i += 1
26 | }
27 | sum
28 | }
29 |
30 | }
31 |
32 | class RRBVectorPrependStringBenchmark extends RRBVectorAbstractPrependBenchmark[String] with VectorGeneratorType.StringGenerator {
33 | val ref = ""
34 |
35 | def prepend(vec: RRBVector[String], n: Int, times: Int): Int = {
36 | var i = 0
37 | var v: RRBVector[String] = null
38 | var sum = 0
39 | while (i < times) {
40 | v = vec
41 | var j = 0
42 | while (j < n) {
43 | v = ref +: vec
44 | j += 1
45 | }
46 | sum += v.length
47 | i += 1
48 | }
49 | sum
50 | }
51 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/rrbvector/unbalanced1/RRBVectorAppendBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.rrbvector.unbalanced1
2 |
3 | import scala.collection.immutable.rrbvector.RRBVector
4 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.AppendBenchmarks
5 | import scala.collection.immutable.vectorutils._
6 |
7 |
8 | abstract class RRBVectorAbstractAppendBenchmark[A] extends AppendBenchmarks[A] with RRBVectorAbstractBenchmark[A]
9 |
10 | class RRBVectorAppendIntBenchmark extends RRBVectorAbstractAppendBenchmark[Int] with VectorGeneratorType.IntGenerator {
11 |
12 | def append(vec: RRBVector[Int], n: Int): Int = {
13 | var v = vec
14 | var i = 0
15 | while (i < n) {
16 | v = vec :+ 0
17 | i += 1
18 | }
19 | v.length
20 | }
21 |
22 | }
23 |
24 | class RRBVectorAppendStringBenchmark extends RRBVectorAbstractAppendBenchmark[String] with VectorGeneratorType.StringGenerator {
25 | val ref = ""
26 |
27 | def append(vec: RRBVector[String], n: Int): Int = {
28 | var v = vec
29 | var i = 0
30 | while (i < n) {
31 | v = vec :+ ref
32 | i += 1
33 | }
34 | v.length
35 | }
36 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/rrbvector/unbalanced1/RRBVectorApplyBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.rrbvector.unbalanced1
2 |
3 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.ApplyBenchmarks
4 | import scala.collection.immutable.vectorutils.VectorGeneratorType
5 |
6 |
7 | abstract class RRBVectorAbstractApplyBenchmark[A] extends ApplyBenchmarks[A] with RRBVectorAbstractBenchmark[A]
8 |
9 | class RRBVectorApplyIntBenchmark extends RRBVectorAbstractApplyBenchmark[Int] with VectorGeneratorType.IntGenerator
10 |
11 | class RRBVectorApplyStringBenchmark extends RRBVectorAbstractApplyBenchmark[String] with VectorGeneratorType.StringGenerator
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/rrbvector/unbalanced1/RRBVectorBuilderBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.rrbvector.unbalanced1
2 |
3 | import scala.collection.immutable.rrbvector.RRBVector
4 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.BuilderBenchmarks
5 | import scala.collection.immutable.vectorutils.VectorGeneratorType
6 |
7 | abstract class RRBVectorAbstractBuilderBenchmark[A] extends BuilderBenchmarks[A] with RRBVectorAbstractBenchmark[A] {
8 | def buildVector(n: Int): Int = {
9 | var i = 0
10 | var b = RRBVector.newBuilder[A]
11 | val e = element(0)
12 | while (i < n) {
13 | b += e
14 | i += 1
15 | }
16 | b.result().length
17 | }
18 | }
19 |
20 | class RRBVectorBuilderIntBenchmark extends RRBVectorAbstractBuilderBenchmark[Int] with VectorGeneratorType.IntGenerator
21 |
22 | class RRBVectorBuilderStringBenchmark extends RRBVectorAbstractBuilderBenchmark[String] with VectorGeneratorType.StringGenerator
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/rrbvector/unbalanced1/RRBVectorConcatenationBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.rrbvector.unbalanced1
2 |
3 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.{Concatenation2Benchmarks, ConcatenationBenchmarks}
4 | import scala.collection.immutable.vectorutils.VectorGeneratorType
5 |
6 | abstract class RRBVectorAbstractConcatenationBenchmark[A] extends ConcatenationBenchmarks[A] with RRBVectorAbstractBenchmark[A]
7 |
8 | class RRBVectorConcatenationIntBenchmark extends RRBVectorAbstractConcatenationBenchmark[Int] with VectorGeneratorType.IntGenerator
9 |
10 | class RRBVectorConcatenationStringBenchmark extends RRBVectorAbstractConcatenationBenchmark[String] with VectorGeneratorType.StringGenerator
11 |
12 |
13 | abstract class RRBVectorAbstractConcatenation2Benchmark[A] extends Concatenation2Benchmarks[A] with RRBVectorAbstractBenchmark[A]
14 |
15 | class RRBVectorConcatenation2IntBenchmark extends RRBVectorAbstractConcatenation2Benchmark[Int] with VectorGeneratorType.IntGenerator
16 |
17 | class RRBVectorConcatenation2StringBenchmark extends RRBVectorAbstractConcatenation2Benchmark[String] with VectorGeneratorType.StringGenerator
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/rrbvector/unbalanced1/RRBVectorIterationBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.rrbvector.unbalanced1
2 |
3 | import scala.collection.immutable.vectorbenchmarks._
4 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.IterationBenchmarks
5 | import scala.collection.immutable.vectorutils.VectorGeneratorType
6 |
7 | abstract class RRBVectorAbstractIterationBenchmark[A] extends IterationBenchmarks[A] with RRBVectorAbstractBenchmark[A]
8 |
9 | class RRBVectorIterationIntBenchmark extends RRBVectorAbstractIterationBenchmark[Int] with VectorGeneratorType.IntGenerator
10 |
11 | class RRBVectorIterationStringBenchmark extends RRBVectorAbstractIterationBenchmark[String] with VectorGeneratorType.StringGenerator
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/rrbvector/unbalanced1/RRBVectorMemoryAllocation.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.rrbvector.unbalanced1
2 |
3 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.MemoryAllocation
4 | import scala.collection.immutable.vectorutils.VectorGeneratorType
5 |
6 |
7 | abstract class RRBVectorAbstractMemoryAllocation[A] extends MemoryAllocation[A] with RRBVectorAbstractBenchmark[A]
8 |
9 | class RRBVectorIntMemoryAllocation extends RRBVectorAbstractMemoryAllocation[Int] with VectorGeneratorType.IntGenerator
10 |
11 | class RRBVectorStringMemoryAllocation extends RRBVectorAbstractMemoryAllocation[String] with VectorGeneratorType.StringGenerator
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/rrbvector/unbalanced1/RRBVectorParMapBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.rrbvector.unbalanced1
2 |
3 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.ParMapBenchmarks
4 | import scala.collection.immutable.vectorutils.VectorGeneratorType
5 |
6 |
7 | abstract class RRBVectorAbstractParMapBenchmark[A] extends ParMapBenchmarks[A] with RRBVectorAbstractBenchmark[A]
8 |
9 | class RRBVectorParMapIntBenchmark extends RRBVectorAbstractParMapBenchmark[Int] with VectorGeneratorType.IntGenerator
10 |
11 | class RRBVectorParMapStringBenchmark extends RRBVectorAbstractParMapBenchmark[String] with VectorGeneratorType.StringGenerator
12 |
13 |
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/rrbvector/unbalanced1/RRBVectorSplitBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.rrbvector.unbalanced1
2 |
3 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.SplitBenchmarks
4 | import scala.collection.immutable.vectorutils.VectorGeneratorType
5 |
6 |
7 | abstract class RRBVectorAbstractSplitBenchmark[A] extends SplitBenchmarks[A] with RRBVectorAbstractBenchmark[A]
8 |
9 | class RRBVectorSplitIntBenchmark extends RRBVectorAbstractSplitBenchmark[Int] with VectorGeneratorType.IntGenerator
10 |
11 | class RRBVectorSplitStringBenchmark extends RRBVectorAbstractSplitBenchmark[String] with VectorGeneratorType.StringGenerator
12 |
13 |
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/rrbvector/unbalanced1/RRBVectorUpdateBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.rrbvector.unbalanced1
2 |
3 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.UpdateBenchmarks
4 | import scala.collection.immutable.vectorutils.VectorGeneratorType
5 |
6 |
7 | abstract class RRBVectorAbstractUpdateBenchmark[A] extends UpdateBenchmarks[A] with RRBVectorAbstractBenchmark[A]
8 |
9 | class RRBVectorUpdateIntBenchmark extends RRBVectorAbstractUpdateBenchmark[Int] with VectorGeneratorType.IntGenerator
10 |
11 | class RRBVectorUpdateStringBenchmark extends RRBVectorAbstractUpdateBenchmark[String] with VectorGeneratorType.StringGenerator
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/rrbvector/xunbalanced/RRBVectorAbstractBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.rrbvector.xunbalanced
2 |
3 | import org.scalameter.Gen
4 |
5 | import scala.collection.immutable.rrbvector.RRBVector
6 | import scala.collection.immutable.vectorbenchmarks.BaseVectorBenchmark
7 | import scala.collection.immutable.vectorutils.BaseVectorGenerator.RRBVectorGenerator
8 |
9 | trait RRBVectorAbstractBenchmark[A] extends BaseVectorBenchmark[A] with RRBVectorGenerator[A] {
10 | override def minHeight = 3
11 |
12 | override def generateVectors(from: Int, to: Int, by: Int, sizesName: String) = sizes(from, to, by, sizesName).map(((size) => randomVectorOfSize(size)(defaultVectorConfig(111))));
13 |
14 | def generateVectors2(from: Int, to: Int, by: Int): Gen[(Vec, Vec)] = {
15 | for {
16 | size1 <- sizes(from, to, by, "size1")
17 | size2 <- sizes(from, to, by, "size2")
18 | } yield (randomVectorOfSize(size1)(defaultVectorConfig(111)), randomVectorOfSize(size2)(defaultVectorConfig(111)))
19 | }
20 |
21 | override def vectorName: String = if (RRBVector.compileAssertions) throw new IllegalStateException("RRBVector.compileAssertions must be false to run benchmarks.") else super.vectorName.+("XUnbalanced")
22 | }
23 |
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/rrbvector/xunbalanced/RRBVectorAbstractPrependBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.rrbvector.xunbalanced
2 |
3 | import scala.collection.immutable.rrbvector.RRBVector
4 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.PrependBenchmarks
5 | import scala.collection.immutable.vectorutils._
6 |
7 |
8 | abstract class RRBVectorAbstractPrependBenchmark[A] extends PrependBenchmarks[A] with RRBVectorAbstractBenchmark[A]
9 |
10 | class RRBVectorPrependIntBenchmark extends RRBVectorAbstractPrependBenchmark[Int] with VectorGeneratorType.IntGenerator {
11 |
12 |
13 | def prepend(vec: RRBVector[Int], n: Int, times: Int): Int = {
14 | var i = 0
15 | var v: RRBVector[Int] = vec
16 | var sum = 0
17 | while (i < times) {
18 | v = vec
19 | var j = 0
20 | while (j < n) {
21 | v = 0 +: vec
22 | j += 1
23 | }
24 | sum += v.length
25 | i += 1
26 | }
27 | sum
28 | }
29 |
30 | }
31 |
32 | class RRBVectorPrependStringBenchmark extends RRBVectorAbstractPrependBenchmark[String] with VectorGeneratorType.StringGenerator {
33 | val ref = ""
34 |
35 | def prepend(vec: RRBVector[String], n: Int, times: Int): Int = {
36 | var i = 0
37 | var v: RRBVector[String] = null
38 | var sum = 0
39 | while (i < times) {
40 | v = vec
41 | var j = 0
42 | while (j < n) {
43 | v = ref +: vec
44 | j += 1
45 | }
46 | sum += v.length
47 | i += 1
48 | }
49 | sum
50 | }
51 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/rrbvector/xunbalanced/RRBVectorAppendBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.rrbvector.xunbalanced
2 |
3 | import scala.collection.immutable.rrbvector.RRBVector
4 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.AppendBenchmarks
5 | import scala.collection.immutable.vectorutils._
6 |
7 |
8 | abstract class RRBVectorAbstractAppendBenchmark[A] extends AppendBenchmarks[A] with RRBVectorAbstractBenchmark[A]
9 |
10 | class RRBVectorAppendIntBenchmark extends RRBVectorAbstractAppendBenchmark[Int] with VectorGeneratorType.IntGenerator {
11 |
12 | def append(vec: RRBVector[Int], n: Int): Int = {
13 | var v = vec
14 | var i = 0
15 | while (i < n) {
16 | v = vec :+ 0
17 | i += 1
18 | }
19 | v.length
20 | }
21 |
22 | }
23 |
24 | class RRBVectorAppendStringBenchmark extends RRBVectorAbstractAppendBenchmark[String] with VectorGeneratorType.StringGenerator {
25 | val ref = ""
26 |
27 | def append(vec: RRBVector[String], n: Int): Int = {
28 | var v = vec
29 | var i = 0
30 | while (i < n) {
31 | v = vec :+ ref
32 | i += 1
33 | }
34 | v.length
35 | }
36 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/rrbvector/xunbalanced/RRBVectorApplyBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.rrbvector.xunbalanced
2 |
3 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.ApplyBenchmarks
4 | import scala.collection.immutable.vectorutils.VectorGeneratorType
5 |
6 |
7 | abstract class RRBVectorAbstractApplyBenchmark[A] extends ApplyBenchmarks[A] with RRBVectorAbstractBenchmark[A]
8 |
9 | class RRBVectorApplyIntBenchmark extends RRBVectorAbstractApplyBenchmark[Int] with VectorGeneratorType.IntGenerator
10 |
11 | class RRBVectorApplyStringBenchmark extends RRBVectorAbstractApplyBenchmark[String] with VectorGeneratorType.StringGenerator
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/rrbvector/xunbalanced/RRBVectorBuilderBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.rrbvector.xunbalanced
2 |
3 | import scala.collection.immutable.rrbvector.RRBVector
4 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.BuilderBenchmarks
5 | import scala.collection.immutable.vectorutils.VectorGeneratorType
6 |
7 | abstract class RRBVectorAbstractBuilderBenchmark[A] extends BuilderBenchmarks[A] with RRBVectorAbstractBenchmark[A] {
8 | def buildVector(n: Int): Int = {
9 | var i = 0
10 | var b = RRBVector.newBuilder[A]
11 | val e = element(0)
12 | while (i < n) {
13 | b += e
14 | i += 1
15 | }
16 | b.result().length
17 | }
18 | }
19 |
20 | class RRBVectorBuilderIntBenchmark extends RRBVectorAbstractBuilderBenchmark[Int] with VectorGeneratorType.IntGenerator
21 |
22 | class RRBVectorBuilderStringBenchmark extends RRBVectorAbstractBuilderBenchmark[String] with VectorGeneratorType.StringGenerator
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/rrbvector/xunbalanced/RRBVectorConcatenationBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.rrbvector.xunbalanced
2 |
3 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.{Concatenation2Benchmarks, ConcatenationBenchmarks}
4 | import scala.collection.immutable.vectorutils.VectorGeneratorType
5 |
6 | abstract class RRBVectorAbstractConcatenationBenchmark[A] extends ConcatenationBenchmarks[A] with RRBVectorAbstractBenchmark[A]
7 |
8 | class RRBVectorConcatenationIntBenchmark extends RRBVectorAbstractConcatenationBenchmark[Int] with VectorGeneratorType.IntGenerator
9 |
10 | class RRBVectorConcatenationStringBenchmark extends RRBVectorAbstractConcatenationBenchmark[String] with VectorGeneratorType.StringGenerator
11 |
12 |
13 | abstract class RRBVectorAbstractConcatenation2Benchmark[A] extends Concatenation2Benchmarks[A] with RRBVectorAbstractBenchmark[A]
14 |
15 | class RRBVectorConcatenation2IntBenchmark extends RRBVectorAbstractConcatenation2Benchmark[Int] with VectorGeneratorType.IntGenerator
16 |
17 | class RRBVectorConcatenation2StringBenchmark extends RRBVectorAbstractConcatenation2Benchmark[String] with VectorGeneratorType.StringGenerator
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/rrbvector/xunbalanced/RRBVectorIterationBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.rrbvector.xunbalanced
2 |
3 | import scala.collection.immutable.vectorbenchmarks._
4 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.IterationBenchmarks
5 | import scala.collection.immutable.vectorutils.VectorGeneratorType
6 |
7 | abstract class RRBVectorAbstractIterationBenchmark[A] extends IterationBenchmarks[A] with RRBVectorAbstractBenchmark[A]
8 |
9 | class RRBVectorIterationIntBenchmark extends RRBVectorAbstractIterationBenchmark[Int] with VectorGeneratorType.IntGenerator
10 |
11 | class RRBVectorIterationStringBenchmark extends RRBVectorAbstractIterationBenchmark[String] with VectorGeneratorType.StringGenerator
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/rrbvector/xunbalanced/RRBVectorMemoryAllocation.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.rrbvector.xunbalanced
2 |
3 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.MemoryAllocation
4 | import scala.collection.immutable.vectorutils.VectorGeneratorType
5 |
6 |
7 | abstract class RRBVectorAbstractMemoryAllocation[A] extends MemoryAllocation[A] with RRBVectorAbstractBenchmark[A]
8 |
9 | class RRBVectorIntMemoryAllocation extends RRBVectorAbstractMemoryAllocation[Int] with VectorGeneratorType.IntGenerator
10 |
11 | class RRBVectorStringMemoryAllocation extends RRBVectorAbstractMemoryAllocation[String] with VectorGeneratorType.StringGenerator
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/rrbvector/xunbalanced/RRBVectorParMapBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.rrbvector.xunbalanced
2 |
3 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.ParMapBenchmarks
4 | import scala.collection.immutable.vectorutils.VectorGeneratorType
5 |
6 |
7 | abstract class RRBVectorAbstractParMapBenchmark[A] extends ParMapBenchmarks[A] with RRBVectorAbstractBenchmark[A]
8 |
9 | class RRBVectorParMapIntBenchmark extends RRBVectorAbstractParMapBenchmark[Int] with VectorGeneratorType.IntGenerator
10 |
11 | class RRBVectorParMapStringBenchmark extends RRBVectorAbstractParMapBenchmark[String] with VectorGeneratorType.StringGenerator
12 |
13 |
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/rrbvector/xunbalanced/RRBVectorSplitBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.rrbvector.xunbalanced
2 |
3 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.SplitBenchmarks
4 | import scala.collection.immutable.vectorutils.VectorGeneratorType
5 |
6 |
7 | abstract class RRBVectorAbstractSplitBenchmark[A] extends SplitBenchmarks[A] with RRBVectorAbstractBenchmark[A]
8 |
9 | class RRBVectorSplitIntBenchmark extends RRBVectorAbstractSplitBenchmark[Int] with VectorGeneratorType.IntGenerator
10 |
11 | class RRBVectorSplitStringBenchmark extends RRBVectorAbstractSplitBenchmark[String] with VectorGeneratorType.StringGenerator
12 |
13 |
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/rrbvector/xunbalanced/RRBVectorUpdateBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.rrbvector.xunbalanced
2 |
3 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.UpdateBenchmarks
4 | import scala.collection.immutable.vectorutils.VectorGeneratorType
5 |
6 |
7 | abstract class RRBVectorAbstractUpdateBenchmark[A] extends UpdateBenchmarks[A] with RRBVectorAbstractBenchmark[A]
8 |
9 | class RRBVectorUpdateIntBenchmark extends RRBVectorAbstractUpdateBenchmark[Int] with VectorGeneratorType.IntGenerator
10 |
11 | class RRBVectorUpdateStringBenchmark extends RRBVectorAbstractUpdateBenchmark[String] with VectorGeneratorType.StringGenerator
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/vector/VectorAppendBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.vector
2 |
3 | import org.scalameter.{Gen, PerformanceTest}
4 | import org.scalameter.PerformanceTest.OfflineRegressionReport
5 |
6 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.AppendBenchmarks
7 | import scala.collection.immutable.vectorutils.VectorGeneratorType
8 |
9 |
10 | abstract class VectorAbstractAppendBenchmark[A] extends AppendBenchmarks[A] with VectorBenchmark[A]
11 |
12 | class VectorAppendIntBenchmark extends VectorAbstractAppendBenchmark[Int] with VectorGeneratorType.IntGenerator {
13 |
14 | def append(vec: Vector[Int], n: Int): Int = {
15 | var v = vec
16 | var i = 0
17 | while (i < n) {
18 | v = vec :+ 0
19 | i += 1
20 | }
21 | v.length
22 | }
23 |
24 | }
25 |
26 | class VectorAppendStringBenchmark extends VectorAbstractAppendBenchmark[String] with VectorGeneratorType.StringGenerator {
27 | val ref = ""
28 |
29 | def append(vec: Vector[String], n: Int): Int = {
30 | var v = vec
31 | var i = 0
32 | while (i < n) {
33 | v = vec :+ ref
34 | i += 1
35 | }
36 | v.length
37 | }
38 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/vector/VectorApplyBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.vector
2 |
3 | import org.scalameter.Gen
4 |
5 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.ApplyBenchmarks
6 | import scala.collection.immutable.vectorutils.VectorGeneratorType
7 |
8 |
9 | abstract class VectorAbstractApplyBenchmark[A] extends ApplyBenchmarks[A] with VectorBenchmark[A]
10 |
11 | class VectorApplyIntBenchmark extends VectorAbstractApplyBenchmark[Int] with VectorGeneratorType.IntGenerator
12 |
13 | class VectorApplyStringBenchmark extends VectorAbstractApplyBenchmark[String] with VectorGeneratorType.StringGenerator
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/vector/VectorBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.vector
2 |
3 | import org.scalameter.Gen
4 |
5 | import scala.collection.immutable.Vector
6 | import scala.collection.immutable.vectorbenchmarks.BaseVectorBenchmark
7 | import scala.collection.immutable.vectorutils.BaseVectorGenerator
8 |
9 |
10 | trait VectorBenchmark[A] extends BaseVectorBenchmark[A] with BaseVectorGenerator.VectorGenerator[A] {
11 |
12 | override def generateVectors(from: Int, to: Int, by: Int, sizesName: String): Gen[Vector[A]] =
13 | for {
14 | size <- sizes(from, to, by, sizesName)
15 | } yield Vector.tabulate(size)(element)
16 |
17 | def generateVectors2(from: Int, to: Int, by: Int): Gen[(Vec, Vec)] = {
18 | for {
19 | size1 <- sizes(from, to, by, "size1")
20 | size2 <- sizes(from, to, by, "size2")
21 | } yield (tabulatedVector(size1), tabulatedVector(size2))
22 | }
23 |
24 | }
25 |
26 |
27 |
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/vector/VectorBuilderBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.vector
2 |
3 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.BuilderBenchmarks
4 | import scala.collection.immutable.vectorutils.VectorGeneratorType
5 |
6 |
7 | abstract class VectorAbstractBuilderBenchmark[A] extends BuilderBenchmarks[A] with VectorBenchmark[A] {
8 | def buildVector(n: Int): Int = {
9 | var i = 0
10 | var b = Vector.newBuilder[A]
11 | val e = element(0)
12 | while (i < n) {
13 | b += e
14 | i += 1
15 |
16 | }
17 | b.result().length
18 | }
19 | }
20 |
21 | class VectorBuilderIntBenchmark extends VectorAbstractBuilderBenchmark[Int] with VectorGeneratorType.IntGenerator
22 |
23 | class VectorBuilderStringBenchmark extends VectorAbstractBuilderBenchmark[String] with VectorGeneratorType.StringGenerator
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/vector/VectorConcatenationBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.vector
2 |
3 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.ConcatenationBenchmarks
4 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.Concatenation2Benchmarks
5 | import scala.collection.immutable.vectorutils.VectorGeneratorType
6 |
7 | abstract class VectorAbstractConcatenationBenchmark[A] extends ConcatenationBenchmarks[A] with VectorBenchmark[A] {
8 | // Used in immutable.vector to bound the sizes
9 | override def to(n: Int): Int = math.min(n, 20000)
10 |
11 | override def points = super.points / 2
12 | }
13 |
14 | class VectorConcatenationIntBenchmark extends VectorAbstractConcatenationBenchmark[Int] with VectorGeneratorType.IntGenerator
15 |
16 | class VectorConcatenationStringBenchmark extends VectorAbstractConcatenationBenchmark[String] with VectorGeneratorType.StringGenerator
17 |
18 |
19 | abstract class VectorAbstractConcatenation2Benchmark[A] extends Concatenation2Benchmarks[A] with VectorBenchmark[A]
20 |
21 | class VectorConcatenation2IntBenchmark extends VectorAbstractConcatenation2Benchmark[Int] with VectorGeneratorType.IntGenerator
22 |
23 | class VectorConcatenation2StringBenchmark extends VectorAbstractConcatenation2Benchmark[String] with VectorGeneratorType.StringGenerator
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/vector/VectorIterationBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.vector
2 |
3 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.IterationBenchmarks
4 | import scala.collection.immutable.vectorbenchmarks._
5 | import scala.collection.immutable.vectorutils.VectorGeneratorType
6 |
7 | abstract class VectorAbstractIterationBenchmark[A] extends IterationBenchmarks[A] with VectorBenchmark[A]
8 |
9 | class VectorIterationIntBenchmark extends VectorAbstractIterationBenchmark[Int] with VectorGeneratorType.IntGenerator
10 |
11 | class VectorIterationStringBenchmark extends VectorAbstractIterationBenchmark[String] with VectorGeneratorType.StringGenerator
12 |
13 |
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/vector/VectorMemoryAllocation.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.vector
2 |
3 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.MemoryAllocation
4 | import scala.collection.immutable.vectorutils.VectorGeneratorType
5 |
6 |
7 | abstract class VectorAbstractMemoryAllocation[A] extends MemoryAllocation[A] with VectorBenchmark[A]
8 |
9 | class VectorIntMemoryAllocation extends VectorAbstractMemoryAllocation[Int] with VectorGeneratorType.IntGenerator
10 |
11 | class VectorStringMemoryAllocation extends VectorAbstractMemoryAllocation[String] with VectorGeneratorType.StringGenerator
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/vector/VectorParMapBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.vector
2 |
3 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.ParMapBenchmarks
4 | import scala.collection.immutable.vectorutils.VectorGeneratorType
5 |
6 |
7 | abstract class VectorAbstractParMapBenchmark[A] extends ParMapBenchmarks[A] with VectorBenchmark[A]
8 |
9 | class VectorParMapIntBenchmark extends VectorAbstractParMapBenchmark[Int] with VectorGeneratorType.IntGenerator
10 |
11 | class VectorParMapStringBenchmark extends VectorAbstractParMapBenchmark[String] with VectorGeneratorType.StringGenerator
12 |
13 |
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/vector/VectorPrependBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.vector
2 |
3 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.PrependBenchmarks
4 | import scala.collection.immutable.vectorutils._
5 |
6 |
7 | abstract class VectorAbstractPrependBenchmark[A] extends PrependBenchmarks[A] with VectorBenchmark[A]
8 |
9 | class VectorPrependIntBenchmark extends VectorAbstractPrependBenchmark[Int] with VectorGeneratorType.IntGenerator {
10 |
11 | def prepend(vec: Vector[Int], n: Int, times: Int): Int = {
12 | var i = 0
13 | var v: Vector[Int] = vec
14 | var sum = 0
15 | while (i < times) {
16 | v = vec
17 | var j = 0
18 | while (j < n) {
19 | v = 0 +: vec
20 | j += 1
21 | }
22 | sum += v.length
23 | i += 1
24 | }
25 | sum
26 | }
27 |
28 | }
29 |
30 | class VectorPrependStringBenchmark extends VectorAbstractPrependBenchmark[String] with VectorGeneratorType.StringGenerator {
31 | val ref = ""
32 |
33 | def prepend(vec: Vector[String], n: Int, times: Int): Int = {
34 | var i = 0
35 | var v: Vector[String] = null
36 | var sum = 0
37 | while (i < times) {
38 | v = vec
39 | var j = 0
40 | while (j < n) {
41 | v = ref +: vec
42 | j += 1
43 | }
44 | sum += v.length
45 | i += 1
46 | }
47 | sum
48 | }
49 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/vector/VectorSplitBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.vector
2 |
3 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.SplitBenchmarks
4 | import scala.collection.immutable.vectorutils.VectorGeneratorType
5 |
6 |
7 | abstract class VectorAbstractSplitBenchmark[A] extends SplitBenchmarks[A] with VectorBenchmark[A]
8 |
9 | class VectorSplitIntBenchmark extends VectorAbstractSplitBenchmark[Int] with VectorGeneratorType.IntGenerator
10 |
11 | class VectorSplitStringBenchmark extends VectorAbstractSplitBenchmark[String] with VectorGeneratorType.StringGenerator
12 |
13 |
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorbenchmarks/vector/VectorUpdateBenchmark.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorbenchmarks.vector
2 |
3 |
4 | import scala.collection.immutable.vectorbenchmarks.genericbenchmarks.UpdateBenchmarks
5 | import scala.collection.immutable.vectorutils.VectorGeneratorType
6 |
7 |
8 | abstract class VectorAbstractUpdateBenchmark[A] extends UpdateBenchmarks[A] with VectorBenchmark[A]
9 |
10 | class VectorUpdateIntBenchmark extends VectorAbstractUpdateBenchmark[Int] with VectorGeneratorType.IntGenerator
11 |
12 | class VectorUpdateStringBenchmark extends VectorAbstractUpdateBenchmark[String] with VectorGeneratorType.StringGenerator
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectortests/QuickTest.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectortests
2 |
3 | import scala.collection.immutable.rrbvector.{RRBVectorIterator, RRBVector}
4 | import scala.collection.immutable.vectorutils.{BaseVectorGenerator, VectorGeneratorType}
5 | import scala.collection.immutable.vectorutils.generated.rrbvector._
6 |
7 |
8 | object QuickTest extends App {
9 |
10 | val n = 32768
11 | val seed = 111
12 |
13 | def f(x: Int) = -x
14 |
15 | val vector = (new BaseVectorGenerator.RRBVectorGenerator[Int] with VectorGeneratorType.IntGenerator).randomVectorOfSize(n)(BaseVectorGenerator.defaultVectorConfig(seed))
16 | val parVec = vector.par map f
17 |
18 | println(vector)
19 | println(parVec)
20 |
21 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectortests/cowarray/CowArrayTest.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectortests.cowarray
2 |
3 | import scala.collection.immutable.vectorbenchmarks.cowarray.CowArrayGenerator
4 | import scala.collection.immutable.vectortests.VectorSpec
5 | import scala.collection.immutable.vectorutils.VectorGeneratorType
6 |
7 | abstract class CowArrayTest[A] extends VectorSpec[A] with CowArrayGenerator[A]
8 |
9 | class IntCowArrayTest extends CowArrayTest[Int] with VectorGeneratorType.IntGenerator
10 |
11 | class StringCowArrayTest extends CowArrayTest[String] with VectorGeneratorType.StringGenerator
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectortests/fingertree/FingerTreeSeqTest.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectortests.fingertree
2 |
3 |
4 | import scala.collection.immutable.vectorbenchmarks.fingertree.FingerTreeSeqGenerator
5 | import scala.collection.immutable.vectortests.VectorSpec
6 | import scala.collection.immutable.vectorutils.VectorGeneratorType
7 |
8 | abstract class FingerTreeSeqTest[A] extends VectorSpec[A] with FingerTreeSeqGenerator[A]
9 |
10 | class IntFingerTreeSeqTest extends FingerTreeSeqTest[Int] with VectorGeneratorType.IntGenerator
11 |
12 | class StringFingerTreeSeqTest extends FingerTreeSeqTest[String] with VectorGeneratorType.StringGenerator
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectortests/generated/rrbvector/complete/block128/RRBVectorTest_c_128.scala:
--------------------------------------------------------------------------------
1 | package scala {
2 | package collection {
3 | package immutable {
4 | package vectortests {
5 | package generated {
6 | package rrbvector.complete.block128 {
7 | import scala.collection.immutable.vectorutils.generated.rrbvector.complete.block128._
8 |
9 | import scala.collection.immutable.vectortests._
10 |
11 | import scala.collection.immutable.vectorutils._
12 |
13 | abstract class RRBVectorTest_c_128[A] extends VectorSpec[A] with RRBVectorGenerator_c_128[A]
14 |
15 | class IntRRBVector_c_128Test extends RRBVectorTest_c_128[Int] with VectorGeneratorType.IntGenerator
16 |
17 | class StringRRBVector_c_128Test extends RRBVectorTest_c_128[String] with VectorGeneratorType.StringGenerator
18 | }
19 | }
20 | }
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectortests/generated/rrbvector/complete/block128/RRBVectorTest_c_128_asserted.scala:
--------------------------------------------------------------------------------
1 | package scala {
2 | package collection {
3 | package immutable {
4 | package vectortests {
5 | package generated {
6 | package rrbvector.complete.block128 {
7 | import scala.collection.immutable.vectorutils.generated.rrbvector.complete.block128._
8 |
9 | import scala.collection.immutable.vectortests._
10 |
11 | import scala.collection.immutable.vectorutils._
12 |
13 | abstract class RRBVectorTest_c_128_asserted[A] extends VectorSpec[A] with RRBVectorGenerator_c_128_asserted[A]
14 |
15 | class IntRRBVector_c_128_assertedTest extends RRBVectorTest_c_128_asserted[Int] with VectorGeneratorType.IntGenerator
16 |
17 | class StringRRBVector_c_128_assertedTest extends RRBVectorTest_c_128_asserted[String] with VectorGeneratorType.StringGenerator
18 | }
19 | }
20 | }
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectortests/generated/rrbvector/complete/block256/RRBVectorTest_c_256.scala:
--------------------------------------------------------------------------------
1 | package scala {
2 | package collection {
3 | package immutable {
4 | package vectortests {
5 | package generated {
6 | package rrbvector.complete.block256 {
7 | import scala.collection.immutable.vectorutils.generated.rrbvector.complete.block256._
8 |
9 | import scala.collection.immutable.vectortests._
10 |
11 | import scala.collection.immutable.vectorutils._
12 |
13 | abstract class RRBVectorTest_c_256[A] extends VectorSpec[A] with RRBVectorGenerator_c_256[A]
14 |
15 | class IntRRBVector_c_256Test extends RRBVectorTest_c_256[Int] with VectorGeneratorType.IntGenerator
16 |
17 | class StringRRBVector_c_256Test extends RRBVectorTest_c_256[String] with VectorGeneratorType.StringGenerator
18 | }
19 | }
20 | }
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectortests/generated/rrbvector/complete/block256/RRBVectorTest_c_256_asserted.scala:
--------------------------------------------------------------------------------
1 | package scala {
2 | package collection {
3 | package immutable {
4 | package vectortests {
5 | package generated {
6 | package rrbvector.complete.block256 {
7 | import scala.collection.immutable.vectorutils.generated.rrbvector.complete.block256._
8 |
9 | import scala.collection.immutable.vectortests._
10 |
11 | import scala.collection.immutable.vectorutils._
12 |
13 | abstract class RRBVectorTest_c_256_asserted[A] extends VectorSpec[A] with RRBVectorGenerator_c_256_asserted[A]
14 |
15 | class IntRRBVector_c_256_assertedTest extends RRBVectorTest_c_256_asserted[Int] with VectorGeneratorType.IntGenerator
16 |
17 | class StringRRBVector_c_256_assertedTest extends RRBVectorTest_c_256_asserted[String] with VectorGeneratorType.StringGenerator
18 | }
19 | }
20 | }
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectortests/generated/rrbvector/complete/block32/RRBVectorTest_c_32.scala:
--------------------------------------------------------------------------------
1 | package scala {
2 | package collection {
3 | package immutable {
4 | package vectortests {
5 | package generated {
6 | package rrbvector.complete.block32 {
7 | import scala.collection.immutable.vectorutils.generated.rrbvector.complete.block32._
8 |
9 | import scala.collection.immutable.vectortests._
10 |
11 | import scala.collection.immutable.vectorutils._
12 |
13 | abstract class RRBVectorTest_c_32[A] extends VectorSpec[A] with RRBVectorGenerator_c_32[A]
14 |
15 | class IntRRBVector_c_32Test extends RRBVectorTest_c_32[Int] with VectorGeneratorType.IntGenerator
16 |
17 | class StringRRBVector_c_32Test extends RRBVectorTest_c_32[String] with VectorGeneratorType.StringGenerator
18 | }
19 | }
20 | }
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectortests/generated/rrbvector/complete/block32/RRBVectorTest_c_32_asserted.scala:
--------------------------------------------------------------------------------
1 | package scala {
2 | package collection {
3 | package immutable {
4 | package vectortests {
5 | package generated {
6 | package rrbvector.complete.block32 {
7 | import scala.collection.immutable.vectorutils.generated.rrbvector.complete.block32._
8 |
9 | import scala.collection.immutable.vectortests._
10 |
11 | import scala.collection.immutable.vectorutils._
12 |
13 | abstract class RRBVectorTest_c_32_asserted[A] extends VectorSpec[A] with RRBVectorGenerator_c_32_asserted[A]
14 |
15 | class IntRRBVector_c_32_assertedTest extends RRBVectorTest_c_32_asserted[Int] with VectorGeneratorType.IntGenerator
16 |
17 | class StringRRBVector_c_32_assertedTest extends RRBVectorTest_c_32_asserted[String] with VectorGeneratorType.StringGenerator
18 | }
19 | }
20 | }
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectortests/generated/rrbvector/complete/block64/RRBVectorTest_c_64.scala:
--------------------------------------------------------------------------------
1 | package scala {
2 | package collection {
3 | package immutable {
4 | package vectortests {
5 | package generated {
6 | package rrbvector.complete.block64 {
7 | import scala.collection.immutable.vectorutils.generated.rrbvector.complete.block64._
8 |
9 | import scala.collection.immutable.vectortests._
10 |
11 | import scala.collection.immutable.vectorutils._
12 |
13 | abstract class RRBVectorTest_c_64[A] extends VectorSpec[A] with RRBVectorGenerator_c_64[A]
14 |
15 | class IntRRBVector_c_64Test extends RRBVectorTest_c_64[Int] with VectorGeneratorType.IntGenerator
16 |
17 | class StringRRBVector_c_64Test extends RRBVectorTest_c_64[String] with VectorGeneratorType.StringGenerator
18 | }
19 | }
20 | }
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectortests/generated/rrbvector/complete/block64/RRBVectorTest_c_64_asserted.scala:
--------------------------------------------------------------------------------
1 | package scala {
2 | package collection {
3 | package immutable {
4 | package vectortests {
5 | package generated {
6 | package rrbvector.complete.block64 {
7 | import scala.collection.immutable.vectorutils.generated.rrbvector.complete.block64._
8 |
9 | import scala.collection.immutable.vectortests._
10 |
11 | import scala.collection.immutable.vectorutils._
12 |
13 | abstract class RRBVectorTest_c_64_asserted[A] extends VectorSpec[A] with RRBVectorGenerator_c_64_asserted[A]
14 |
15 | class IntRRBVector_c_64_assertedTest extends RRBVectorTest_c_64_asserted[Int] with VectorGeneratorType.IntGenerator
16 |
17 | class StringRRBVector_c_64_assertedTest extends RRBVectorTest_c_64_asserted[String] with VectorGeneratorType.StringGenerator
18 | }
19 | }
20 | }
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectortests/generated/rrbvector/quick/block128/RRBVectorTest_q_128.scala:
--------------------------------------------------------------------------------
1 | package scala {
2 | package collection {
3 | package immutable {
4 | package vectortests {
5 | package generated {
6 | package rrbvector.quick.block128 {
7 | import scala.collection.immutable.vectorutils.generated.rrbvector.quick.block128._
8 |
9 | import scala.collection.immutable.vectortests._
10 |
11 | import scala.collection.immutable.vectorutils._
12 |
13 | abstract class RRBVectorTest_q_128[A] extends VectorSpec[A] with RRBVectorGenerator_q_128[A]
14 |
15 | class IntRRBVector_q_128Test extends RRBVectorTest_q_128[Int] with VectorGeneratorType.IntGenerator
16 |
17 | class StringRRBVector_q_128Test extends RRBVectorTest_q_128[String] with VectorGeneratorType.StringGenerator
18 | }
19 | }
20 | }
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectortests/generated/rrbvector/quick/block128/RRBVectorTest_q_128_asserted.scala:
--------------------------------------------------------------------------------
1 | package scala {
2 | package collection {
3 | package immutable {
4 | package vectortests {
5 | package generated {
6 | package rrbvector.quick.block128 {
7 | import scala.collection.immutable.vectorutils.generated.rrbvector.quick.block128._
8 |
9 | import scala.collection.immutable.vectortests._
10 |
11 | import scala.collection.immutable.vectorutils._
12 |
13 | abstract class RRBVectorTest_q_128_asserted[A] extends VectorSpec[A] with RRBVectorGenerator_q_128_asserted[A]
14 |
15 | class IntRRBVector_q_128_assertedTest extends RRBVectorTest_q_128_asserted[Int] with VectorGeneratorType.IntGenerator
16 |
17 | class StringRRBVector_q_128_assertedTest extends RRBVectorTest_q_128_asserted[String] with VectorGeneratorType.StringGenerator
18 | }
19 | }
20 | }
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectortests/generated/rrbvector/quick/block256/RRBVectorTest_q_256.scala:
--------------------------------------------------------------------------------
1 | package scala {
2 | package collection {
3 | package immutable {
4 | package vectortests {
5 | package generated {
6 | package rrbvector.quick.block256 {
7 | import scala.collection.immutable.vectorutils.generated.rrbvector.quick.block256._
8 |
9 | import scala.collection.immutable.vectortests._
10 |
11 | import scala.collection.immutable.vectorutils._
12 |
13 | abstract class RRBVectorTest_q_256[A] extends VectorSpec[A] with RRBVectorGenerator_q_256[A]
14 |
15 | class IntRRBVector_q_256Test extends RRBVectorTest_q_256[Int] with VectorGeneratorType.IntGenerator
16 |
17 | class StringRRBVector_q_256Test extends RRBVectorTest_q_256[String] with VectorGeneratorType.StringGenerator
18 | }
19 | }
20 | }
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectortests/generated/rrbvector/quick/block256/RRBVectorTest_q_256_asserted.scala:
--------------------------------------------------------------------------------
1 | package scala {
2 | package collection {
3 | package immutable {
4 | package vectortests {
5 | package generated {
6 | package rrbvector.quick.block256 {
7 | import scala.collection.immutable.vectorutils.generated.rrbvector.quick.block256._
8 |
9 | import scala.collection.immutable.vectortests._
10 |
11 | import scala.collection.immutable.vectorutils._
12 |
13 | abstract class RRBVectorTest_q_256_asserted[A] extends VectorSpec[A] with RRBVectorGenerator_q_256_asserted[A]
14 |
15 | class IntRRBVector_q_256_assertedTest extends RRBVectorTest_q_256_asserted[Int] with VectorGeneratorType.IntGenerator
16 |
17 | class StringRRBVector_q_256_assertedTest extends RRBVectorTest_q_256_asserted[String] with VectorGeneratorType.StringGenerator
18 | }
19 | }
20 | }
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectortests/generated/rrbvector/quick/block32/RRBVectorTest_q_32.scala:
--------------------------------------------------------------------------------
1 | package scala {
2 | package collection {
3 | package immutable {
4 | package vectortests {
5 | package generated {
6 | package rrbvector.quick.block32 {
7 | import scala.collection.immutable.vectorutils.generated.rrbvector.quick.block32._
8 |
9 | import scala.collection.immutable.vectortests._
10 |
11 | import scala.collection.immutable.vectorutils._
12 |
13 | abstract class RRBVectorTest_q_32[A] extends VectorSpec[A] with RRBVectorGenerator_q_32[A]
14 |
15 | class IntRRBVector_q_32Test extends RRBVectorTest_q_32[Int] with VectorGeneratorType.IntGenerator
16 |
17 | class StringRRBVector_q_32Test extends RRBVectorTest_q_32[String] with VectorGeneratorType.StringGenerator
18 | }
19 | }
20 | }
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectortests/generated/rrbvector/quick/block32/RRBVectorTest_q_32_asserted.scala:
--------------------------------------------------------------------------------
1 | package scala {
2 | package collection {
3 | package immutable {
4 | package vectortests {
5 | package generated {
6 | package rrbvector.quick.block32 {
7 | import scala.collection.immutable.vectorutils.generated.rrbvector.quick.block32._
8 |
9 | import scala.collection.immutable.vectortests._
10 |
11 | import scala.collection.immutable.vectorutils._
12 |
13 | abstract class RRBVectorTest_q_32_asserted[A] extends VectorSpec[A] with RRBVectorGenerator_q_32_asserted[A]
14 |
15 | class IntRRBVector_q_32_assertedTest extends RRBVectorTest_q_32_asserted[Int] with VectorGeneratorType.IntGenerator
16 |
17 | class StringRRBVector_q_32_assertedTest extends RRBVectorTest_q_32_asserted[String] with VectorGeneratorType.StringGenerator
18 | }
19 | }
20 | }
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectortests/generated/rrbvector/quick/block64/RRBVectorTest_q_64.scala:
--------------------------------------------------------------------------------
1 | package scala {
2 | package collection {
3 | package immutable {
4 | package vectortests {
5 | package generated {
6 | package rrbvector.quick.block64 {
7 | import scala.collection.immutable.vectorutils.generated.rrbvector.quick.block64._
8 |
9 | import scala.collection.immutable.vectortests._
10 |
11 | import scala.collection.immutable.vectorutils._
12 |
13 | abstract class RRBVectorTest_q_64[A] extends VectorSpec[A] with RRBVectorGenerator_q_64[A]
14 |
15 | class IntRRBVector_q_64Test extends RRBVectorTest_q_64[Int] with VectorGeneratorType.IntGenerator
16 |
17 | class StringRRBVector_q_64Test extends RRBVectorTest_q_64[String] with VectorGeneratorType.StringGenerator
18 | }
19 | }
20 | }
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectortests/generated/rrbvector/quick/block64/RRBVectorTest_q_64_asserted.scala:
--------------------------------------------------------------------------------
1 | package scala {
2 | package collection {
3 | package immutable {
4 | package vectortests {
5 | package generated {
6 | package rrbvector.quick.block64 {
7 | import scala.collection.immutable.vectorutils.generated.rrbvector.quick.block64._
8 |
9 | import scala.collection.immutable.vectortests._
10 |
11 | import scala.collection.immutable.vectorutils._
12 |
13 | abstract class RRBVectorTest_q_64_asserted[A] extends VectorSpec[A] with RRBVectorGenerator_q_64_asserted[A]
14 |
15 | class IntRRBVector_q_64_assertedTest extends RRBVectorTest_q_64_asserted[Int] with VectorGeneratorType.IntGenerator
16 |
17 | class StringRRBVector_q_64_assertedTest extends RRBVectorTest_q_64_asserted[String] with VectorGeneratorType.StringGenerator
18 | }
19 | }
20 | }
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectortests/redblack/RedBlackTest.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectortests.redblack
2 |
3 | import scala.collection.immutable.vectorbenchmarks.redblack.RedBlackSeqGenerator
4 | import scala.collection.immutable.vectortests.VectorSpec
5 | import scala.collection.immutable.vectorutils.VectorGeneratorType
6 |
7 | abstract class RedBlackSeqTest[A] extends VectorSpec[A] with RedBlackSeqGenerator[A]
8 |
9 | class IntRedBlackSeqTest extends RedBlackSeqTest[Int] with VectorGeneratorType.IntGenerator
10 |
11 | class StringRedBlackSeqTest extends RedBlackSeqTest[String] with VectorGeneratorType.StringGenerator
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectortests/rrbvector/RRBVectorTest.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectortests.rrbvector
2 |
3 | import scala.collection.immutable.vectortests.VectorSpec
4 | import scala.collection.immutable.vectorutils.{VectorGeneratorType, BaseVectorGenerator}
5 |
6 |
7 | abstract class RRBVectorTest[A] extends VectorSpec[A] with BaseVectorGenerator.RRBVectorGenerator[A]
8 |
9 | class IntRRBVectorTest extends RRBVectorTest[Int] with VectorGeneratorType.IntGenerator
10 |
11 | class StringRRBVectorTest extends RRBVectorTest[String] with VectorGeneratorType.StringGenerator
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectortests/vector/VectorTest.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectortests.vector
2 |
3 | import scala.collection.immutable.vectortests.VectorSpec
4 | import scala.collection.immutable.vectorutils.{VectorGeneratorType, BaseVectorGenerator}
5 |
6 |
7 | abstract class VectorTest[A] extends VectorSpec[A] with BaseVectorGenerator.VectorGenerator[A] {
8 | override def isRRBVectorImplementation = false
9 | }
10 |
11 | class IntVectorTest extends VectorTest[Int] with VectorGeneratorType.IntGenerator
12 |
13 | class StringVectorTest extends VectorTest[String] with VectorGeneratorType.StringGenerator
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorutils/VectorGeneratorType.scala:
--------------------------------------------------------------------------------
1 | package scala.collection.immutable.vectorutils
2 |
3 |
4 | trait VectorGeneratorType[A] {
5 | def element(n: Int): A
6 |
7 | def vectorTypeName: String
8 |
9 | protected final def mapBenchFunCompute(x: Int): Int = {
10 | Math.cos(3.1415 + Math.cos(1.0 + Math.sin(2.0 + Math.cos(Math.sin(Math.sin(Math.cos(x + 1.0))))))).toInt
11 | }
12 |
13 | protected final def mapBenchFun2Compute(x: Int): Int = {
14 | // This is a inefficient implementation of prime testing
15 | // that aims to generate unbalanced workloads
16 | assert(x >= 0)
17 | for (i <- 2 until (x + 2)) {
18 | if (x % i == 0) {
19 | return i
20 | }
21 | }
22 | x
23 | }
24 | }
25 |
26 | object VectorGeneratorType {
27 |
28 | trait IntGenerator extends VectorGeneratorType[Int] {
29 |
30 | @inline final def element(n: Int): Int = n
31 |
32 | final def mapSelfFun(x: Int) = x
33 |
34 | final def mapBenchFun(x: Int) = {
35 | mapBenchFunCompute(1)
36 | }
37 |
38 | final def mapBenchFun2(x: Int): Int = {
39 | mapBenchFun2Compute(x)
40 | }
41 |
42 | final def mapFun1(x: Int): Int = x % 3
43 |
44 | final def mapFun2(x: Int): Int = (x + 1) % 534564634
45 |
46 | final def mapFun3(x: Int): Int = (x * x) % 534564634
47 |
48 |
49 | final def vectorTypeName: String = "Int"
50 | }
51 |
52 | trait StringGenerator extends VectorGeneratorType[String] {
53 |
54 | @inline final def element(n: Int): String = n.toString
55 |
56 | final def mapSelfFun(x: String) = x
57 |
58 | final def mapBenchFun(x: String) = {
59 | mapBenchFunCompute(x.hashCode).toString
60 | }
61 |
62 | final def mapBenchFun2(x: String): String = {
63 | val y = try {
64 | Integer.parseInt(x)
65 | } catch {
66 | case _: NumberFormatException => x.hashCode
67 | }
68 | mapBenchFun2Compute(y).toString
69 | }
70 |
71 | final def mapFun1(x: String): String = {
72 | val split = x splitAt (x.length / 2)
73 | split._1 + split._2
74 | }
75 |
76 | final def mapFun2(x: String): String = s"${x.length + 10}"
77 |
78 | final def mapFun3(x: String): String = s"${x.hashCode}"
79 |
80 | final def vectorTypeName: String = "String"
81 | }
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorutils/VectorOps.scala:
--------------------------------------------------------------------------------
1 | package scala.collection
2 | package immutable.vectorutils
3 |
4 | /**
5 | * Created by nicolasstucki on 06/10/2014.
6 | */
7 | trait VectorOps[A] {
8 | type Vec <: IndexedSeq[A]
9 |
10 | def element(n: Int): A
11 |
12 | def newBuilder(): mutable.Builder[A, Vec]
13 |
14 | def emptyVector: Vec
15 |
16 | def plus(vec: Vec, elem: A): Vec
17 |
18 | def plus(elem: A, vec: Vec): Vec
19 |
20 | def plusPlus(vec1: Vec, vec2: Vec): Vec
21 |
22 | def take(vec: Vec, n: Int): Vec
23 |
24 | def drop(vec: Vec, n: Int): Vec
25 | }
26 |
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorutils/generated/rrbvector/complete/block128/RRBVectorGenerator_c_128.scala:
--------------------------------------------------------------------------------
1 | package scala {
2 | package collection {
3 | package immutable {
4 | package vectorutils {
5 | package generated {
6 | package rrbvector {
7 | package complete {
8 | package block128 {
9 | trait RRBVectorGenerator_c_128[A] extends BaseVectorGenerator[A] {
10 | import scala.collection.immutable.generated.rrbvector.complete.block128._;
11 | override type Vec = RRBVector_c_128[A];
12 | final def vectorClassName: String = "RRBVector_c_128";
13 | final override def newBuilder() = RRBVector_c_128.newBuilder[A];
14 | final override def tabulatedVector(n: Int): Vec = RRBVector_c_128.tabulate(n)(element);
15 | final override def rangedVector(start: Int, end: Int): Vec = RRBVector_c_128.range(start, end).map(element);
16 | final override def emptyVector: Vec = RRBVector_c_128.empty[A];
17 | override def iterator(vec: Vec, start: Int, end: Int) = {
18 | val it = new RRBVectorIterator_c_128[A](start, end);
19 | it.initIteratorFrom(vec);
20 | it
21 | };
22 | final override def plus(vec: Vec, elem: A): Vec = vec.:+(elem);
23 | final override def plus(elem: A, vec: Vec): Vec = vec.+:(elem);
24 | final override def plusPlus(vec1: Vec, vec2: Vec): Vec = vec1.++(vec2);
25 | final override def take(vec: Vec, n: Int): Vec = vec.take(n);
26 | final override def drop(vec: Vec, n: Int): Vec = vec.drop(n)
27 | }
28 | }
29 | }
30 | }
31 | }
32 | }
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorutils/generated/rrbvector/complete/block128/RRBVectorGenerator_c_128_asserted.scala:
--------------------------------------------------------------------------------
1 | package scala {
2 | package collection {
3 | package immutable {
4 | package vectorutils {
5 | package generated {
6 | package rrbvector {
7 | package complete {
8 | package block128 {
9 | trait RRBVectorGenerator_c_128_asserted[A] extends BaseVectorGenerator[A] {
10 | import scala.collection.immutable.generated.rrbvector.complete.block128._;
11 | override type Vec = RRBVector_c_128_asserted[A];
12 | final def vectorClassName: String = "RRBVector_c_128_asserted";
13 | final override def newBuilder() = RRBVector_c_128_asserted.newBuilder[A];
14 | final override def tabulatedVector(n: Int): Vec = RRBVector_c_128_asserted.tabulate(n)(element);
15 | final override def rangedVector(start: Int, end: Int): Vec = RRBVector_c_128_asserted.range(start, end).map(element);
16 | final override def emptyVector: Vec = RRBVector_c_128_asserted.empty[A];
17 | override def iterator(vec: Vec, start: Int, end: Int) = {
18 | val it = new RRBVectorIterator_c_128_asserted[A](start, end);
19 | it.initIteratorFrom(vec);
20 | it
21 | };
22 | final override def plus(vec: Vec, elem: A): Vec = vec.:+(elem);
23 | final override def plus(elem: A, vec: Vec): Vec = vec.+:(elem);
24 | final override def plusPlus(vec1: Vec, vec2: Vec): Vec = vec1.++(vec2);
25 | final override def take(vec: Vec, n: Int): Vec = vec.take(n);
26 | final override def drop(vec: Vec, n: Int): Vec = vec.drop(n)
27 | }
28 | }
29 | }
30 | }
31 | }
32 | }
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorutils/generated/rrbvector/complete/block256/RRBVectorGenerator_c_256.scala:
--------------------------------------------------------------------------------
1 | package scala {
2 | package collection {
3 | package immutable {
4 | package vectorutils {
5 | package generated {
6 | package rrbvector {
7 | package complete {
8 | package block256 {
9 | trait RRBVectorGenerator_c_256[A] extends BaseVectorGenerator[A] {
10 | import scala.collection.immutable.generated.rrbvector.complete.block256._;
11 | override type Vec = RRBVector_c_256[A];
12 | final def vectorClassName: String = "RRBVector_c_256";
13 | final override def newBuilder() = RRBVector_c_256.newBuilder[A];
14 | final override def tabulatedVector(n: Int): Vec = RRBVector_c_256.tabulate(n)(element);
15 | final override def rangedVector(start: Int, end: Int): Vec = RRBVector_c_256.range(start, end).map(element);
16 | final override def emptyVector: Vec = RRBVector_c_256.empty[A];
17 | override def iterator(vec: Vec, start: Int, end: Int) = {
18 | val it = new RRBVectorIterator_c_256[A](start, end);
19 | it.initIteratorFrom(vec);
20 | it
21 | };
22 | final override def plus(vec: Vec, elem: A): Vec = vec.:+(elem);
23 | final override def plus(elem: A, vec: Vec): Vec = vec.+:(elem);
24 | final override def plusPlus(vec1: Vec, vec2: Vec): Vec = vec1.++(vec2);
25 | final override def take(vec: Vec, n: Int): Vec = vec.take(n);
26 | final override def drop(vec: Vec, n: Int): Vec = vec.drop(n)
27 | }
28 | }
29 | }
30 | }
31 | }
32 | }
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorutils/generated/rrbvector/complete/block256/RRBVectorGenerator_c_256_asserted.scala:
--------------------------------------------------------------------------------
1 | package scala {
2 | package collection {
3 | package immutable {
4 | package vectorutils {
5 | package generated {
6 | package rrbvector {
7 | package complete {
8 | package block256 {
9 | trait RRBVectorGenerator_c_256_asserted[A] extends BaseVectorGenerator[A] {
10 | import scala.collection.immutable.generated.rrbvector.complete.block256._;
11 | override type Vec = RRBVector_c_256_asserted[A];
12 | final def vectorClassName: String = "RRBVector_c_256_asserted";
13 | final override def newBuilder() = RRBVector_c_256_asserted.newBuilder[A];
14 | final override def tabulatedVector(n: Int): Vec = RRBVector_c_256_asserted.tabulate(n)(element);
15 | final override def rangedVector(start: Int, end: Int): Vec = RRBVector_c_256_asserted.range(start, end).map(element);
16 | final override def emptyVector: Vec = RRBVector_c_256_asserted.empty[A];
17 | override def iterator(vec: Vec, start: Int, end: Int) = {
18 | val it = new RRBVectorIterator_c_256_asserted[A](start, end);
19 | it.initIteratorFrom(vec);
20 | it
21 | };
22 | final override def plus(vec: Vec, elem: A): Vec = vec.:+(elem);
23 | final override def plus(elem: A, vec: Vec): Vec = vec.+:(elem);
24 | final override def plusPlus(vec1: Vec, vec2: Vec): Vec = vec1.++(vec2);
25 | final override def take(vec: Vec, n: Int): Vec = vec.take(n);
26 | final override def drop(vec: Vec, n: Int): Vec = vec.drop(n)
27 | }
28 | }
29 | }
30 | }
31 | }
32 | }
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorutils/generated/rrbvector/complete/block32/RRBVectorGenerator_c_32.scala:
--------------------------------------------------------------------------------
1 | package scala {
2 | package collection {
3 | package immutable {
4 | package vectorutils {
5 | package generated {
6 | package rrbvector {
7 | package complete {
8 | package block32 {
9 | trait RRBVectorGenerator_c_32[A] extends BaseVectorGenerator[A] {
10 | import scala.collection.immutable.generated.rrbvector.complete.block32._;
11 | override type Vec = RRBVector_c_32[A];
12 | final def vectorClassName: String = "RRBVector_c_32";
13 | final override def newBuilder() = RRBVector_c_32.newBuilder[A];
14 | final override def tabulatedVector(n: Int): Vec = RRBVector_c_32.tabulate(n)(element);
15 | final override def rangedVector(start: Int, end: Int): Vec = RRBVector_c_32.range(start, end).map(element);
16 | final override def emptyVector: Vec = RRBVector_c_32.empty[A];
17 | override def iterator(vec: Vec, start: Int, end: Int) = {
18 | val it = new RRBVectorIterator_c_32[A](start, end);
19 | it.initIteratorFrom(vec);
20 | it
21 | };
22 | final override def plus(vec: Vec, elem: A): Vec = vec.:+(elem);
23 | final override def plus(elem: A, vec: Vec): Vec = vec.+:(elem);
24 | final override def plusPlus(vec1: Vec, vec2: Vec): Vec = vec1.++(vec2);
25 | final override def take(vec: Vec, n: Int): Vec = vec.take(n);
26 | final override def drop(vec: Vec, n: Int): Vec = vec.drop(n)
27 | }
28 | }
29 | }
30 | }
31 | }
32 | }
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorutils/generated/rrbvector/complete/block32/RRBVectorGenerator_c_32_asserted.scala:
--------------------------------------------------------------------------------
1 | package scala {
2 | package collection {
3 | package immutable {
4 | package vectorutils {
5 | package generated {
6 | package rrbvector {
7 | package complete {
8 | package block32 {
9 | trait RRBVectorGenerator_c_32_asserted[A] extends BaseVectorGenerator[A] {
10 | import scala.collection.immutable.generated.rrbvector.complete.block32._;
11 | override type Vec = RRBVector_c_32_asserted[A];
12 | final def vectorClassName: String = "RRBVector_c_32_asserted";
13 | final override def newBuilder() = RRBVector_c_32_asserted.newBuilder[A];
14 | final override def tabulatedVector(n: Int): Vec = RRBVector_c_32_asserted.tabulate(n)(element);
15 | final override def rangedVector(start: Int, end: Int): Vec = RRBVector_c_32_asserted.range(start, end).map(element);
16 | final override def emptyVector: Vec = RRBVector_c_32_asserted.empty[A];
17 | override def iterator(vec: Vec, start: Int, end: Int) = {
18 | val it = new RRBVectorIterator_c_32_asserted[A](start, end);
19 | it.initIteratorFrom(vec);
20 | it
21 | };
22 | final override def plus(vec: Vec, elem: A): Vec = vec.:+(elem);
23 | final override def plus(elem: A, vec: Vec): Vec = vec.+:(elem);
24 | final override def plusPlus(vec1: Vec, vec2: Vec): Vec = vec1.++(vec2);
25 | final override def take(vec: Vec, n: Int): Vec = vec.take(n);
26 | final override def drop(vec: Vec, n: Int): Vec = vec.drop(n)
27 | }
28 | }
29 | }
30 | }
31 | }
32 | }
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorutils/generated/rrbvector/complete/block64/RRBVectorGenerator_c_64.scala:
--------------------------------------------------------------------------------
1 | package scala {
2 | package collection {
3 | package immutable {
4 | package vectorutils {
5 | package generated {
6 | package rrbvector {
7 | package complete {
8 | package block64 {
9 | trait RRBVectorGenerator_c_64[A] extends BaseVectorGenerator[A] {
10 | import scala.collection.immutable.generated.rrbvector.complete.block64._;
11 | override type Vec = RRBVector_c_64[A];
12 | final def vectorClassName: String = "RRBVector_c_64";
13 | final override def newBuilder() = RRBVector_c_64.newBuilder[A];
14 | final override def tabulatedVector(n: Int): Vec = RRBVector_c_64.tabulate(n)(element);
15 | final override def rangedVector(start: Int, end: Int): Vec = RRBVector_c_64.range(start, end).map(element);
16 | final override def emptyVector: Vec = RRBVector_c_64.empty[A];
17 | override def iterator(vec: Vec, start: Int, end: Int) = {
18 | val it = new RRBVectorIterator_c_64[A](start, end);
19 | it.initIteratorFrom(vec);
20 | it
21 | };
22 | final override def plus(vec: Vec, elem: A): Vec = vec.:+(elem);
23 | final override def plus(elem: A, vec: Vec): Vec = vec.+:(elem);
24 | final override def plusPlus(vec1: Vec, vec2: Vec): Vec = vec1.++(vec2);
25 | final override def take(vec: Vec, n: Int): Vec = vec.take(n);
26 | final override def drop(vec: Vec, n: Int): Vec = vec.drop(n)
27 | }
28 | }
29 | }
30 | }
31 | }
32 | }
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorutils/generated/rrbvector/complete/block64/RRBVectorGenerator_c_64_asserted.scala:
--------------------------------------------------------------------------------
1 | package scala {
2 | package collection {
3 | package immutable {
4 | package vectorutils {
5 | package generated {
6 | package rrbvector {
7 | package complete {
8 | package block64 {
9 | trait RRBVectorGenerator_c_64_asserted[A] extends BaseVectorGenerator[A] {
10 | import scala.collection.immutable.generated.rrbvector.complete.block64._;
11 | override type Vec = RRBVector_c_64_asserted[A];
12 | final def vectorClassName: String = "RRBVector_c_64_asserted";
13 | final override def newBuilder() = RRBVector_c_64_asserted.newBuilder[A];
14 | final override def tabulatedVector(n: Int): Vec = RRBVector_c_64_asserted.tabulate(n)(element);
15 | final override def rangedVector(start: Int, end: Int): Vec = RRBVector_c_64_asserted.range(start, end).map(element);
16 | final override def emptyVector: Vec = RRBVector_c_64_asserted.empty[A];
17 | override def iterator(vec: Vec, start: Int, end: Int) = {
18 | val it = new RRBVectorIterator_c_64_asserted[A](start, end);
19 | it.initIteratorFrom(vec);
20 | it
21 | };
22 | final override def plus(vec: Vec, elem: A): Vec = vec.:+(elem);
23 | final override def plus(elem: A, vec: Vec): Vec = vec.+:(elem);
24 | final override def plusPlus(vec1: Vec, vec2: Vec): Vec = vec1.++(vec2);
25 | final override def take(vec: Vec, n: Int): Vec = vec.take(n);
26 | final override def drop(vec: Vec, n: Int): Vec = vec.drop(n)
27 | }
28 | }
29 | }
30 | }
31 | }
32 | }
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorutils/generated/rrbvector/quick/block128/RRBVectorGenerator_q_128.scala:
--------------------------------------------------------------------------------
1 | package scala {
2 | package collection {
3 | package immutable {
4 | package vectorutils {
5 | package generated {
6 | package rrbvector {
7 | package quick {
8 | package block128 {
9 | trait RRBVectorGenerator_q_128[A] extends BaseVectorGenerator[A] {
10 | import scala.collection.immutable.generated.rrbvector.quick.block128._;
11 | override type Vec = RRBVector_q_128[A];
12 | final def vectorClassName: String = "RRBVector_q_128";
13 | final override def newBuilder() = RRBVector_q_128.newBuilder[A];
14 | final override def tabulatedVector(n: Int): Vec = RRBVector_q_128.tabulate(n)(element);
15 | final override def rangedVector(start: Int, end: Int): Vec = RRBVector_q_128.range(start, end).map(element);
16 | final override def emptyVector: Vec = RRBVector_q_128.empty[A];
17 | override def iterator(vec: Vec, start: Int, end: Int) = {
18 | val it = new RRBVectorIterator_q_128[A](start, end);
19 | it.initIteratorFrom(vec);
20 | it
21 | };
22 | final override def plus(vec: Vec, elem: A): Vec = vec.:+(elem);
23 | final override def plus(elem: A, vec: Vec): Vec = vec.+:(elem);
24 | final override def plusPlus(vec1: Vec, vec2: Vec): Vec = vec1.++(vec2);
25 | final override def take(vec: Vec, n: Int): Vec = vec.take(n);
26 | final override def drop(vec: Vec, n: Int): Vec = vec.drop(n)
27 | }
28 | }
29 | }
30 | }
31 | }
32 | }
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorutils/generated/rrbvector/quick/block128/RRBVectorGenerator_q_128_asserted.scala:
--------------------------------------------------------------------------------
1 | package scala {
2 | package collection {
3 | package immutable {
4 | package vectorutils {
5 | package generated {
6 | package rrbvector {
7 | package quick {
8 | package block128 {
9 | trait RRBVectorGenerator_q_128_asserted[A] extends BaseVectorGenerator[A] {
10 | import scala.collection.immutable.generated.rrbvector.quick.block128._;
11 | override type Vec = RRBVector_q_128_asserted[A];
12 | final def vectorClassName: String = "RRBVector_q_128_asserted";
13 | final override def newBuilder() = RRBVector_q_128_asserted.newBuilder[A];
14 | final override def tabulatedVector(n: Int): Vec = RRBVector_q_128_asserted.tabulate(n)(element);
15 | final override def rangedVector(start: Int, end: Int): Vec = RRBVector_q_128_asserted.range(start, end).map(element);
16 | final override def emptyVector: Vec = RRBVector_q_128_asserted.empty[A];
17 | override def iterator(vec: Vec, start: Int, end: Int) = {
18 | val it = new RRBVectorIterator_q_128_asserted[A](start, end);
19 | it.initIteratorFrom(vec);
20 | it
21 | };
22 | final override def plus(vec: Vec, elem: A): Vec = vec.:+(elem);
23 | final override def plus(elem: A, vec: Vec): Vec = vec.+:(elem);
24 | final override def plusPlus(vec1: Vec, vec2: Vec): Vec = vec1.++(vec2);
25 | final override def take(vec: Vec, n: Int): Vec = vec.take(n);
26 | final override def drop(vec: Vec, n: Int): Vec = vec.drop(n)
27 | }
28 | }
29 | }
30 | }
31 | }
32 | }
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorutils/generated/rrbvector/quick/block256/RRBVectorGenerator_q_256.scala:
--------------------------------------------------------------------------------
1 | package scala {
2 | package collection {
3 | package immutable {
4 | package vectorutils {
5 | package generated {
6 | package rrbvector {
7 | package quick {
8 | package block256 {
9 | trait RRBVectorGenerator_q_256[A] extends BaseVectorGenerator[A] {
10 | import scala.collection.immutable.generated.rrbvector.quick.block256._;
11 | override type Vec = RRBVector_q_256[A];
12 | final def vectorClassName: String = "RRBVector_q_256";
13 | final override def newBuilder() = RRBVector_q_256.newBuilder[A];
14 | final override def tabulatedVector(n: Int): Vec = RRBVector_q_256.tabulate(n)(element);
15 | final override def rangedVector(start: Int, end: Int): Vec = RRBVector_q_256.range(start, end).map(element);
16 | final override def emptyVector: Vec = RRBVector_q_256.empty[A];
17 | override def iterator(vec: Vec, start: Int, end: Int) = {
18 | val it = new RRBVectorIterator_q_256[A](start, end);
19 | it.initIteratorFrom(vec);
20 | it
21 | };
22 | final override def plus(vec: Vec, elem: A): Vec = vec.:+(elem);
23 | final override def plus(elem: A, vec: Vec): Vec = vec.+:(elem);
24 | final override def plusPlus(vec1: Vec, vec2: Vec): Vec = vec1.++(vec2);
25 | final override def take(vec: Vec, n: Int): Vec = vec.take(n);
26 | final override def drop(vec: Vec, n: Int): Vec = vec.drop(n)
27 | }
28 | }
29 | }
30 | }
31 | }
32 | }
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorutils/generated/rrbvector/quick/block256/RRBVectorGenerator_q_256_asserted.scala:
--------------------------------------------------------------------------------
1 | package scala {
2 | package collection {
3 | package immutable {
4 | package vectorutils {
5 | package generated {
6 | package rrbvector {
7 | package quick {
8 | package block256 {
9 | trait RRBVectorGenerator_q_256_asserted[A] extends BaseVectorGenerator[A] {
10 | import scala.collection.immutable.generated.rrbvector.quick.block256._;
11 | override type Vec = RRBVector_q_256_asserted[A];
12 | final def vectorClassName: String = "RRBVector_q_256_asserted";
13 | final override def newBuilder() = RRBVector_q_256_asserted.newBuilder[A];
14 | final override def tabulatedVector(n: Int): Vec = RRBVector_q_256_asserted.tabulate(n)(element);
15 | final override def rangedVector(start: Int, end: Int): Vec = RRBVector_q_256_asserted.range(start, end).map(element);
16 | final override def emptyVector: Vec = RRBVector_q_256_asserted.empty[A];
17 | override def iterator(vec: Vec, start: Int, end: Int) = {
18 | val it = new RRBVectorIterator_q_256_asserted[A](start, end);
19 | it.initIteratorFrom(vec);
20 | it
21 | };
22 | final override def plus(vec: Vec, elem: A): Vec = vec.:+(elem);
23 | final override def plus(elem: A, vec: Vec): Vec = vec.+:(elem);
24 | final override def plusPlus(vec1: Vec, vec2: Vec): Vec = vec1.++(vec2);
25 | final override def take(vec: Vec, n: Int): Vec = vec.take(n);
26 | final override def drop(vec: Vec, n: Int): Vec = vec.drop(n)
27 | }
28 | }
29 | }
30 | }
31 | }
32 | }
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorutils/generated/rrbvector/quick/block32/RRBVectorGenerator_q_32.scala:
--------------------------------------------------------------------------------
1 | package scala {
2 | package collection {
3 | package immutable {
4 | package vectorutils {
5 | package generated {
6 | package rrbvector {
7 | package quick {
8 | package block32 {
9 | trait RRBVectorGenerator_q_32[A] extends BaseVectorGenerator[A] {
10 | import scala.collection.immutable.generated.rrbvector.quick.block32._;
11 | override type Vec = RRBVector_q_32[A];
12 | final def vectorClassName: String = "RRBVector_q_32";
13 | final override def newBuilder() = RRBVector_q_32.newBuilder[A];
14 | final override def tabulatedVector(n: Int): Vec = RRBVector_q_32.tabulate(n)(element);
15 | final override def rangedVector(start: Int, end: Int): Vec = RRBVector_q_32.range(start, end).map(element);
16 | final override def emptyVector: Vec = RRBVector_q_32.empty[A];
17 | override def iterator(vec: Vec, start: Int, end: Int) = {
18 | val it = new RRBVectorIterator_q_32[A](start, end);
19 | it.initIteratorFrom(vec);
20 | it
21 | };
22 | final override def plus(vec: Vec, elem: A): Vec = vec.:+(elem);
23 | final override def plus(elem: A, vec: Vec): Vec = vec.+:(elem);
24 | final override def plusPlus(vec1: Vec, vec2: Vec): Vec = vec1.++(vec2);
25 | final override def take(vec: Vec, n: Int): Vec = vec.take(n);
26 | final override def drop(vec: Vec, n: Int): Vec = vec.drop(n)
27 | }
28 | }
29 | }
30 | }
31 | }
32 | }
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorutils/generated/rrbvector/quick/block32/RRBVectorGenerator_q_32_asserted.scala:
--------------------------------------------------------------------------------
1 | package scala {
2 | package collection {
3 | package immutable {
4 | package vectorutils {
5 | package generated {
6 | package rrbvector {
7 | package quick {
8 | package block32 {
9 | trait RRBVectorGenerator_q_32_asserted[A] extends BaseVectorGenerator[A] {
10 | import scala.collection.immutable.generated.rrbvector.quick.block32._;
11 | override type Vec = RRBVector_q_32_asserted[A];
12 | final def vectorClassName: String = "RRBVector_q_32_asserted";
13 | final override def newBuilder() = RRBVector_q_32_asserted.newBuilder[A];
14 | final override def tabulatedVector(n: Int): Vec = RRBVector_q_32_asserted.tabulate(n)(element);
15 | final override def rangedVector(start: Int, end: Int): Vec = RRBVector_q_32_asserted.range(start, end).map(element);
16 | final override def emptyVector: Vec = RRBVector_q_32_asserted.empty[A];
17 | override def iterator(vec: Vec, start: Int, end: Int) = {
18 | val it = new RRBVectorIterator_q_32_asserted[A](start, end);
19 | it.initIteratorFrom(vec);
20 | it
21 | };
22 | final override def plus(vec: Vec, elem: A): Vec = vec.:+(elem);
23 | final override def plus(elem: A, vec: Vec): Vec = vec.+:(elem);
24 | final override def plusPlus(vec1: Vec, vec2: Vec): Vec = vec1.++(vec2);
25 | final override def take(vec: Vec, n: Int): Vec = vec.take(n);
26 | final override def drop(vec: Vec, n: Int): Vec = vec.drop(n)
27 | }
28 | }
29 | }
30 | }
31 | }
32 | }
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorutils/generated/rrbvector/quick/block64/RRBVectorGenerator_q_64.scala:
--------------------------------------------------------------------------------
1 | package scala {
2 | package collection {
3 | package immutable {
4 | package vectorutils {
5 | package generated {
6 | package rrbvector {
7 | package quick {
8 | package block64 {
9 | trait RRBVectorGenerator_q_64[A] extends BaseVectorGenerator[A] {
10 | import scala.collection.immutable.generated.rrbvector.quick.block64._;
11 | override type Vec = RRBVector_q_64[A];
12 | final def vectorClassName: String = "RRBVector_q_64";
13 | final override def newBuilder() = RRBVector_q_64.newBuilder[A];
14 | final override def tabulatedVector(n: Int): Vec = RRBVector_q_64.tabulate(n)(element);
15 | final override def rangedVector(start: Int, end: Int): Vec = RRBVector_q_64.range(start, end).map(element);
16 | final override def emptyVector: Vec = RRBVector_q_64.empty[A];
17 | override def iterator(vec: Vec, start: Int, end: Int) = {
18 | val it = new RRBVectorIterator_q_64[A](start, end);
19 | it.initIteratorFrom(vec);
20 | it
21 | };
22 | final override def plus(vec: Vec, elem: A): Vec = vec.:+(elem);
23 | final override def plus(elem: A, vec: Vec): Vec = vec.+:(elem);
24 | final override def plusPlus(vec1: Vec, vec2: Vec): Vec = vec1.++(vec2);
25 | final override def take(vec: Vec, n: Int): Vec = vec.take(n);
26 | final override def drop(vec: Vec, n: Int): Vec = vec.drop(n)
27 | }
28 | }
29 | }
30 | }
31 | }
32 | }
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/src/test/scala/scala/collection/immutable/vectorutils/generated/rrbvector/quick/block64/RRBVectorGenerator_q_64_asserted.scala:
--------------------------------------------------------------------------------
1 | package scala {
2 | package collection {
3 | package immutable {
4 | package vectorutils {
5 | package generated {
6 | package rrbvector {
7 | package quick {
8 | package block64 {
9 | trait RRBVectorGenerator_q_64_asserted[A] extends BaseVectorGenerator[A] {
10 | import scala.collection.immutable.generated.rrbvector.quick.block64._;
11 | override type Vec = RRBVector_q_64_asserted[A];
12 | final def vectorClassName: String = "RRBVector_q_64_asserted";
13 | final override def newBuilder() = RRBVector_q_64_asserted.newBuilder[A];
14 | final override def tabulatedVector(n: Int): Vec = RRBVector_q_64_asserted.tabulate(n)(element);
15 | final override def rangedVector(start: Int, end: Int): Vec = RRBVector_q_64_asserted.range(start, end).map(element);
16 | final override def emptyVector: Vec = RRBVector_q_64_asserted.empty[A];
17 | override def iterator(vec: Vec, start: Int, end: Int) = {
18 | val it = new RRBVectorIterator_q_64_asserted[A](start, end);
19 | it.initIteratorFrom(vec);
20 | it
21 | };
22 | final override def plus(vec: Vec, elem: A): Vec = vec.:+(elem);
23 | final override def plus(elem: A, vec: Vec): Vec = vec.+:(elem);
24 | final override def plusPlus(vec1: Vec, vec2: Vec): Vec = vec1.++(vec2);
25 | final override def take(vec: Vec, n: Int): Vec = vec.take(n);
26 | final override def drop(vec: Vec, n: Int): Vec = vec.drop(n)
27 | }
28 | }
29 | }
30 | }
31 | }
32 | }
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------