Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import org.gradle.internal.os.OperatingSystem

plugins {
id 'java'
id 'scala'
id 'me.champeau.jmh' version '0.7.1'
}

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

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

tasks.compileJmhScala.classpath = sourceSets.main.compileClasspath

tasks.compileJmhJava.classpath += files(sourceSets.jmh.scala.classesDirectory)

compileTestJava {
options.compilerArgs += [
'--add-modules', 'jdk.incubator.vector'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.alibaba.fastjson2.JSONObject;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.plokhotnyuk.jsoniter_scala.core.ReaderConfig$;
import com.github.plokhotnyuk.jsoniter_scala.core.package$;
import com.jsoniter.JsonIterator;
import com.jsoniter.any.Any;
import org.openjdk.jmh.annotations.Benchmark;
Expand Down Expand Up @@ -43,6 +45,19 @@ public void setup() throws IOException {
}
}

@Benchmark
public int countUniqueUsersWithDefaultProfile_jsoniter_scala() throws IOException {
Twitter twitter = package$.MODULE$.readFromArray(buffer, ReaderConfig$.MODULE$, Twitter$.MODULE$.codec());
Set<String> defaultUsers = new HashSet<>();
for (Status tweet: twitter.statuses()) {
User user = tweet.user();
if (user.default_profile()) {
defaultUsers.add(user.screen_name());
}
}
return defaultUsers.size();
}

@Benchmark
public int countUniqueUsersWithDefaultProfile_jackson() throws IOException {
JsonNode jacksonJsonNode = objectMapper.readTree(buffer);
Expand Down
14 changes: 14 additions & 0 deletions src/jmh/scala/com/github/piotrrzysko/simdjson/Twitter.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.github.piotrrzysko.simdjson

import com.github.plokhotnyuk.jsoniter_scala.core.JsonValueCodec
import com.github.plokhotnyuk.jsoniter_scala.macros.JsonCodecMaker

case class User(default_profile: Boolean, screen_name: String)

case class Status(user: User)

case class Twitter(statuses: Array[Status])

object Twitter {
val codec: JsonValueCodec[Twitter] = JsonCodecMaker.make
}