Skip to content

Commit

Permalink
Add benchmarking module (close #108)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjben committed Oct 14, 2020
1 parent 5efd96c commit 9961e77
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ Use this SDK with **[Apache Spark][spark]**, **[AWS Lambda][lambda]**, **[Apache
[Setup guide][setup-guide] and [User guide][user-guide] are available on the [Snowplow wiki][snowplow-wiki].
The Scaladoc website of the project can be found [here][scala-doc].

## Benchmarking

This project comes with [sbt-jmh](https://github.com/ktoso/sbt-jmh).

Benchmarks need to be added [here](./benchmark/src/test/scala/com.snowplowanalytics.snowplow.analytics.scalasdk/benchmark/).

They can be run with `sbt "project benchmark" "+jmh:run -i 10 -wi 3 -f2 -t3"`.

To get details about the parameters `jmh:run -h`.

## Copyright and license

The Snowplow Scala Analytics SDK is copyright 2016-2019 Snowplow Analytics Ltd.
Expand Down
6 changes: 6 additions & 0 deletions benchmark/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
sourceDirectory in Jmh := (sourceDirectory in Test).value
classDirectory in Jmh := (classDirectory in Test).value
dependencyClasspath in Jmh := (dependencyClasspath in Test).value
// rewire tasks, so that 'jmh:run' automatically invokes 'jmh:compile' (otherwise a clean 'jmh:run' would fail)
compile in Jmh := (compile in Jmh).dependsOn(compile in Test).value
run in Jmh := (run in Jmh).dependsOn(Keys.compile in Jmh).evaluated
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.snowplowanalytics.snowplow.analytics.scalasdk.benchmark

import org.openjdk.jmh.annotations._

import java.util.concurrent.TimeUnit
import java.util.UUID
import java.time.Instant

import com.snowplowanalytics.snowplow.analytics.scalasdk.Event

@State(Scope.Thread)
@BenchmarkMode(Array(Mode.AverageTime, Mode.Throughput))
@OutputTimeUnit(TimeUnit.MICROSECONDS)
class BenchmarkAnalyticsSDK {
@Benchmark
def ordered(state : States.AtomicEventState): Unit = {
state.event.ordered
}
}

object States {
@State(Scope.Benchmark)
class AtomicEventState {
var event: Event = _

@Setup(Level.Trial)
def init(): Unit = {
val uuid = UUID.randomUUID()
val timestamp = Instant.now()
val vCollector = "2.0.0"
val vTracker = "scala_0.7.0"
event = Event.minimal(uuid, timestamp, vCollector, vTracker)
}
}
}
5 changes: 5 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,8 @@ lazy val root = project.in(file("."))
Dependencies.specs2
)
)

lazy val benchmark = project
.in(file("benchmark"))
.dependsOn(root % "test->test")
.enablePlugins(JmhPlugin)
1 change: 1 addition & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.1")
addSbtPlugin("com.typesafe.sbt" % "sbt-site" % "1.4.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "1.0.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-ghpages" % "0.6.3")
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.0")

0 comments on commit 9961e77

Please sign in to comment.