Skip to content

Commit

Permalink
Create detailed benchmarks about tuples
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine Brunner committed Dec 3, 2019
1 parent 62a0c28 commit 0cdf81e
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 3 deletions.
Empty file removed bench-run/outputs/concat.csv
Empty file.
4 changes: 2 additions & 2 deletions bench-run/src/main/scala/tuples/Apply.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import org.openjdk.jmh.annotations._
import scala.runtime.DynamicTuple

@State(Scope.Thread)
class ApplyBenchmarks {
class Apply {
@Param(Array("1 0"))
var sizeAndIndex: String = _
var tuple: NonEmptyTuple = _
Expand All @@ -17,7 +17,7 @@ class ApplyBenchmarks {
tuple = "elem" *: ()

for (i <- 1 until size)
tuple = "string" *: tuple
tuple = "elem" *: tuple
}

@Benchmark
Expand Down
47 changes: 47 additions & 0 deletions bench-run/src/main/scala/tuples/ArrayOps.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package dotty.tools.benchmarks.tuples

import org.openjdk.jmh.annotations._
import scala.runtime.DynamicTuple

@State(Scope.Thread)
class ArrayOps {
@Param(Array("0"))
var size: Int = _
var tuple: Tuple = _
var array: Array[Object] = _
var iarray: IArray[Object] = _

@Setup
def setup(): Unit = {
tuple = ()

for (i <- 1 to size)
tuple = "elem" *: tuple

array = Array.fill(size)("elem")
iarray = IArray.fill(size)("elem")
}

@Benchmark
def baseline(): Unit = {}

@Benchmark
def toArray(): Array[Object] = {
DynamicTuple.dynamicToArray(tuple)
}

@Benchmark
def toIArray(): IArray[Object] = {
DynamicTuple.dynamicToIArray(tuple)
}

@Benchmark
def fromArray(): Tuple = {
DynamicTuple.dynamicFromArray(array)
}

@Benchmark
def fromIArray(): Tuple = {
DynamicTuple.dynamicFromIArray(iarray)
}
}
2 changes: 1 addition & 1 deletion bench-run/src/main/scala/tuples/Concat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Concat {
val size1 = sizes.split(' ')(0).toInt
val size2 = sizes.split(' ')(1).toInt
tuple1 = tupleOfSize(size1)
tuple1 = tupleOfSize(size2)
tuple2 = tupleOfSize(size2)
array1 = Array.fill(size1)("elem")
array2 = Array.fill(size2)("elem")
}
Expand Down
41 changes: 41 additions & 0 deletions bench-run/src/main/scala/tuples/Cons.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package dotty.tools.benchmarks.tuples

import org.openjdk.jmh.annotations._
import scala.runtime.DynamicTuple

@State(Scope.Thread)
class Cons {
@Param(Array("0"))
var size: Int = _
var tuple: Tuple = _
var array: Array[Object] = _

@Setup
def setup(): Unit = {
tuple = ()

for (i <- 1 to size)
tuple = "elem" *: tuple

array = Array.fill(size)("elem")
}

@Benchmark
def baseline(): Unit = {}

@Benchmark
def normal(): Tuple = {
"elem" *: tuple
}

@Benchmark
def inlined(): Tuple = {
DynamicTuple.dynamicCons("elem", tuple)
}

// This part is here to measure the performance of dong a cons on arrays directly
@Benchmark
def arrayCons(): Array[Object] = {
DynamicTuple.cons$Array("elem", array)
}
}

0 comments on commit 0cdf81e

Please sign in to comment.