Skip to content

Commit 8d26e68

Browse files
committed
Benchmark LCS diff implementation
1 parent c2e8c82 commit 8d26e68

File tree

4 files changed

+85
-3
lines changed

4 files changed

+85
-3
lines changed

.gitignore

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@ syntax: glob
2020
.idea
2121
*.iml
2222

23-
#bsp
24-
.bsp
25-
2623
# building
2724
target
25+
out
2826
build
2927
null
3028
tmp*
@@ -51,3 +49,15 @@ build.log
5149
#ensime
5250
.ensime*
5351
ensime.sbt
52+
53+
# website
54+
site/content/api
55+
site/content/documentation/
56+
site/output
57+
58+
.metals/
59+
.bloop/
60+
.bsp/
61+
metals.sbt
62+
63+
.vscode/settings.json
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package diffson
2+
3+
import org.openjdk.jmh.annotations.State
4+
import org.openjdk.jmh.annotations.Scope
5+
import org.openjdk.jmh.annotations.BenchmarkMode
6+
import org.openjdk.jmh.annotations.Mode
7+
import org.openjdk.jmh.annotations.Fork
8+
import org.openjdk.jmh.annotations.Warmup
9+
import org.openjdk.jmh.annotations.Measurement
10+
11+
import diffson.circe._
12+
import diffson.jsonpatch.lcsdiff._
13+
import diffson.lcs._
14+
15+
import io.circe.syntax._
16+
import io.circe.Json
17+
import org.openjdk.jmh.annotations.Benchmark
18+
19+
@BenchmarkMode(Array(Mode.Throughput))
20+
@State(Scope.Benchmark)
21+
@Fork(value = 1)
22+
@Warmup(iterations = 3, time = 2)
23+
@Measurement(iterations = 5, time = 2)
24+
class PatienceBenchmarks {
25+
26+
implicit val lcs = new Patience[Json]
27+
28+
private def createJson(depth: Int, arrayStep: Int) =
29+
List
30+
.range(depth, 0, -1)
31+
.foldLeft(Json.obj("array" := List.range(0, 1000, arrayStep).map(n => Json.obj("n" := n, "other" := "common")))) {
32+
(acc, idx) =>
33+
Json.obj(s"key$idx" := acc, "other" := arrayStep)
34+
}
35+
36+
def array(size: Int, step: Int) =
37+
Json.obj("array" := List.range(0, size, step))
38+
39+
val deep1 =
40+
createJson(100, 1)
41+
42+
val deep2 =
43+
createJson(100, 2)
44+
45+
val array1 =
46+
array(1000, 2)
47+
48+
val array2 =
49+
array(1000, 1)
50+
51+
@Benchmark
52+
def diffArray() =
53+
diff(array1, array2)
54+
55+
@Benchmark
56+
def diffDeep() =
57+
diff(deep1, deep2)
58+
}

build.sbt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,16 @@ lazy val circe = crossProject(JSPlatform, JVMPlatform, NativePlatform)
9090
)
9191
)
9292
.dependsOn(core, testkit % Test)
93+
94+
lazy val benchmarks = crossProject(JVMPlatform)
95+
.crossType(CrossType.Pure)
96+
.in(file("benchmarks"))
97+
.enablePlugins(NoPublishPlugin, JmhPlugin)
98+
.settings(commonSettings: _*)
99+
.settings(
100+
name := "diffson-benchmarks",
101+
libraryDependencies ++= Seq(
102+
"io.circe" %% "circe-literal" % circeVersion
103+
)
104+
)
105+
.dependsOn(circe)

project/plugins.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ addSbtPlugin("org.typelevel" % "sbt-typelevel" % "0.4.18")
22
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.13.0")
33
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.10")
44
addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.2.0")
5+
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.4")

0 commit comments

Comments
 (0)