Skip to content

Commit

Permalink
support for running jmh with bleep. add first map benchmark.
Browse files Browse the repository at this point in the history
Towards #1
  • Loading branch information
oyvindberg committed Feb 15, 2023
1 parent 99fd339 commit f252dbd
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package farray

import org.junit.Test

import scala.collection.BuildFrom

//format: off
Expand Down Expand Up @@ -103,7 +101,7 @@ object Benchmark:
)

def inputs(base: String, nonEmpty: Boolean = false): (List[List[String]], FArray[FArray[String]], IArray[IArray[String]]) =
val all = (base * 4).toArray.map(_.toString)
val all = (base * 2).toArray.map(_.toString)
val indices = if nonEmpty then all.indices.drop(1) else all.indices
val allList = indices.map(all.take).map(_.toList).toList
val allFArray = FArray.fromIterable(indices.map(all.take).map(FArray.fromArray(_)))
Expand Down Expand Up @@ -169,7 +167,9 @@ object Benchmark:

def timed(title: String)(t: => Unit): Unit = {
val t0 = System.currentTimeMillis()
t
0 to 100 foreach {_ =>
t
}
val td = System.currentTimeMillis() - t0
println(s"$title: $td ms")
}
Expand Down Expand Up @@ -197,7 +197,7 @@ object Benchmark:
test.runAllIArray()
}
}
0 to 1000 foreach { _ =>
0 to 100 foreach { _ =>
tests.foreach { test =>
test.runAllFArray()
test.runAllList()
Expand Down
33 changes: 33 additions & 0 deletions benchmarks/src/scala/farray/CommonParams.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package farray

import org.openjdk.jmh.annotations._
import scala.collection.immutable.BitSet
import java.util.concurrent.TimeUnit
import org.openjdk.jmh.annotations.Benchmark
import scala.collection.immutable.BitSet

@State(Scope.Thread)
@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Fork(
value = 1,
jvmArgs = Array(
"-server",
"-Xms2g",
"-Xmx2g",
"-XX:NewSize=1g",
"-XX:MaxNewSize=1g",
"-XX:InitialCodeCacheSize=512m",
"-XX:ReservedCodeCacheSize=512m",
"-XX:+UseParallelGC",
"-XX:-UseAdaptiveSizePolicy",
"-XX:MaxInlineLevel=20",
"-XX:InlineSmallCode=1500",
"-XX:+AlwaysPreTouch",
"-XX:+UseNUMA",
"-XX:-UseAdaptiveNUMAChunkSizing"
)
)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
abstract class CommonParams
28 changes: 28 additions & 0 deletions benchmarks/src/scala/farray/GenJmh.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package farray

import bleep.*
import bleep.internal.FileUtils
import org.openjdk.jmh.generators.bytecode.JmhBytecodeGenerator

import java.io.File
import java.nio.file.{Files, Path}
import scala.collection.Seq

object GenJmh extends BleepCodegenScript("GenJmh") {
def run(started: Started, commands: Commands, benchmarksRunnerProject: model.CrossProjectName, args: List[String]): Unit = {
val benchmarksProject = model.CrossProjectName(model.ProjectName("benchmarks"), None)

val paths = started.projectPaths(benchmarksRunnerProject)
val sourceDir = paths.sourcesDirs.generated
val resourceDir = paths.resourcesDirs.generated
val classesDir = started.projectPaths(benchmarksProject).classes

// rebuild everything
FileUtils.deleteDirectory(sourceDir)
Files.createDirectories(sourceDir)
FileUtils.deleteDirectory(resourceDir)
Files.createDirectories(resourceDir)

JmhBytecodeGenerator.main(Array(classesDir.toString, sourceDir.toString, resourceDir.toString, "default"))
}
}
19 changes: 19 additions & 0 deletions benchmarks/src/scala/farray/Inputs.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package farray

import org.openjdk.jmh.annotations.{Param, Setup}

abstract class Inputs extends CommonParams {
var listInput: List[String] = _
var farrayInput: FArray[String] = _
var iarrayInput: IArray[String] = _

@Param(Array("1", "10", "100", "1000", "10000", "100000", "1000000"))
var size: Int = 1000

@Setup
def setup(): Unit = {
listInput = List.tabulate(size)(_.toString)
farrayInput = FArray.tabulate(size)(_.toString)
iarrayInput = IArray.tabulate(size)(_.toString)
}
}
9 changes: 9 additions & 0 deletions benchmarks/src/scala/farray/MapBenchmark.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package farray

import org.openjdk.jmh.annotations.Benchmark

class MapBenchmark extends Inputs {
@Benchmark def list(): List[String] = listInput.map(x => x + x)
@Benchmark def farray(): FArray[String] = farrayInput.map(x => x + x)
@Benchmark def iarray(): IArray[String] = iarrayInput.map(x => x + x)
}
15 changes: 14 additions & 1 deletion bleep.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ projects:
dependsOn: farray
extends: template-common
isTestProject: true
benchmarks:
dependsOn: farray
extends: template-common
dependencies:
- org.openjdk.jmh:jmh-generator-bytecode:1.36
- build.bleep::bleep-core:${BLEEP_VERSION}
benchmarks-runner:
dependsOn: benchmarks
extends: template-common
platform:
mainClass: org.openjdk.jmh.Main
sourcegen:
project: benchmarks
main: farray.GenJmh
scripts:
dependencies:
- build.bleep::bleep-plugin-ci-release:${BLEEP_VERSION}
Expand All @@ -24,7 +38,6 @@ projects:
options: -encoding utf8 -feature -unchecked
strict: true
version: 2.13.10

scripts:
my-publish-local:
main: PublishLocal
Expand Down

0 comments on commit f252dbd

Please sign in to comment.