8000 Merge pull request #2 from plokhotnyuk/main · aaron-ds/simdjson-java@021867f · GitHub
[go: up one dir, main page]

Skip to content

Commit 021867f

Browse files
authored
Merge pull request simdjson#2 from plokhotnyuk/main
Add a benchmark for jsoniter-scala
2 parents c496bef + 958122a commit 021867f

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

build.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import org.gradle.internal.os.OperatingSystem
33

44
plugins {
55
id 'java'
6+
id 'scala'
67
id 'me.champeau.jmh' version '0.7.1'
78
}
89

@@ -27,6 +28,8 @@ dependencies {
2728
jmhImplementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.15.2'
2829
jmhImplementation group: 'com.alibaba.fastjson2', name: 'fastjson2', version: '2.0.35'
2930
jmhImplementation group: 'com.jsoniter', name: 'jsoniter', version: '0.9.23'
31+
jmhImplementation group: 'com.github.plokhotnyuk.jsoniter-scala', name: 'jsoniter-scala-core_2.13', version: '2.23.2'
32+
compileOnly group: 'com.github.plokhotnyuk.jsoniter-scala', name: 'jsoniter-scala-macros_2.13', version: '2.23.2'
3033

3134
testImplementation group: 'org.assertj', name: 'assertj-core', version: '3.24.2'
3235
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: junitVersion
@@ -50,6 +53,10 @@ tasks.withType(JavaCompile).configureEach {
5053
options.compilerArgs.add("--add-modules=jdk.incubator.vector")
5154
}
5255

56+
tasks.compileJmhScala.classpath = sourceSets.main.compileClasspath
57+
58+
tasks.compileJmhJava.classpath += files(sourceSets.jmh.scala.classesDirectory)
59+
5360
compileTestJava {
5461
options.compilerArgs += [
5562
'--add-modules', 'jdk.incubator.vector'

src/jmh/java/com/github/piotrrzysko/simdjson/ParseAndSelectBenchmark.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import com.alibaba.fastjson2.JSONObject;
55
import com.fasterxml.jackson.databind.JsonNode;
66
import com.fasterxml.jackson.databind.ObjectMapper;
7+
import com.github.plokhotnyuk.jsoniter_scala.core.ReaderConfig$;
8+
import com.github.plokhotnyuk.jsoniter_scala.core.package$;
79
import com.jsoniter.JsonIterator;
810
import com.jsoniter.any.Any;
911
import org.openjdk.jmh.annotations.Benchmark;
@@ -43,6 +45,19 @@ public void setup() throws IOException {
4345
}
4446
}
4547

48+
@Benchmark
49+
public int countUniqueUsersWithDefaultProfile_jsoniter_scala() throws IOException {
50+
Twitter twitter = package$.MODULE$.readFromArray(buffer, ReaderConfig$.MODULE$, Twitter$.MODULE$.codec());
51+
Set<String> defaultUsers = new HashSet<>();
52+
for (Status tweet: twitter.statuses()) {
53+
User user = tweet.user();
54+
if (user.default_profile()) {
55+
defaultUsers.add(user.screen_name());
56+
}
57+
}
58+
return defaultUsers.size();
59+
}
60+
4661
@Benchmark
4762
public int countUniqueUsersWithDefaultProfile_jackson() throws IOException {
4863
JsonNode jacksonJsonNode = objectMapper.readTree(buffer);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.github.piotrrzysko.simdjson
2+
3+
import com.github.plokhotnyuk.jsoniter_scala.core.JsonValueCodec
4+
import com.github.plokhotnyuk.jsoniter_scala.macros.JsonCodecMaker
5+
6+
case class User(default_profile: Boolean, screen_name: String)
7+
8+
case class Status(user: User)
9+
10+
case class Twitter(statuses: Array[Status])
11+
12+
object Twitter {
13+
val codec: JsonValueCodec[Twitter] = JsonCodecMaker.make
14+
}

0 commit comments

Comments
 (0)
0