-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
benchmark/src/main/scala/net/marek/tyre/benchmark/RegexBenchmark.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package net.marek.tyre.benchmark | ||
|
||
import org.openjdk.jmh.annotations.{Benchmark, Scope, State} | ||
import net.marek.tyre.* | ||
import scala.util.Random | ||
|
||
@State(Scope.Thread) | ||
class RegexBenchmark: | ||
|
||
@Benchmark | ||
def runTyre: Unit = data.foreach(tyreTimeParser.run) | ||
|
||
@Benchmark | ||
def runRegex: Unit = data.foreach: | ||
case regexTimeParser(h, m) => (h.toInt, m.toInt) | ||
|
||
private val tyreTimeParser = | ||
val ht = tyre"[0-1]\d|2[0-3]" | ||
val mt = tyre"[0-5]\d" | ||
val tt = tyre"$ht:$mt".map: t => | ||
val ((h10,h1), _, m10, m1) = t | ||
(h10.toInt * 10 + h1.toInt, m10.toInt * 10 + m1.toInt) | ||
tt.compile() | ||
|
||
private val regexTimeParser = """([0-1]\d|2[0-3]):([0-5]\d)""".r | ||
|
||
private val rand = Random() | ||
private def drawTime = | ||
val h = rand.between(0,24) | ||
val m = rand.between(0,60) | ||
f"$h%02d:$m%02d" | ||
private val data = List.tabulate(100_000)(_ => drawTime) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2") | ||
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.12") | ||
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.7") |