-
Notifications
You must be signed in to change notification settings - Fork 22
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
1 parent
84736d5
commit 394e76c
Showing
111 changed files
with
10,911 additions
and
1,086 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
build | ||
profilers | ||
testdata | ||
hotspot_*.log |
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
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
123 changes: 123 additions & 0 deletions
123
src/jmh/java/org/simdjson/SchemaBasedParseAndSelectBenchmark.java
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,123 @@ | ||
package org.simdjson; | ||
|
||
import com.alibaba.fastjson2.JSON; | ||
import com.fasterxml.jackson.databind.DeserializationFeature; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.github.plokhotnyuk.jsoniter_scala.core.ReaderConfig$; | ||
import com.github.plokhotnyuk.jsoniter_scala.core.package$; | ||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.BenchmarkMode; | ||
import org.openjdk.jmh.annotations.Level; | ||
import org.openjdk.jmh.annotations.Mode; | ||
import org.openjdk.jmh.annotations.OutputTimeUnit; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.Setup; | ||
import org.openjdk.jmh.annotations.State; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import static org.simdjson.SimdJsonPaddingUtil.padded; | ||
|
||
@State(Scope.Benchmark) | ||
@BenchmarkMode(Mode.Throughput) | ||
@OutputTimeUnit(TimeUnit.SECONDS) | ||
public class SchemaBasedParseAndSelectBenchmark { | ||
|
||
private final SimdJsonParser simdJsonParser = new SimdJsonParser(); | ||
private final ObjectMapper objectMapper = new ObjectMapper() | ||
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); | ||
|
||
private byte[] buffer; | ||
private byte[] bufferPadded; | ||
|
||
@Setup(Level.Trial) | ||
public void setup() throws IOException { | ||
try (InputStream is = ParseBenchmark.class.getResourceAsStream("/twitter.json")) { | ||
buffer = is.readAllBytes(); | ||
bufferPadded = padded(buffer); | ||
} | ||
System.out.println("VectorSpecies = " + StructuralIndexer.BYTE_SPECIES); | ||
} | ||
|
||
@Benchmark | ||
public int countUniqueUsersWithDefaultProfile_simdjson() { | ||
Set<String> defaultUsers = new HashSet<>(); | ||
SimdJsonTwitter twitter = simdJsonParser.parse(buffer, buffer.length, SimdJsonTwitter.class); | ||
for (SimdJsonStatus status : twitter.statuses()) { | ||
SimdJsonUser user = status.user(); | ||
if (user.default_profile()) { | ||
defaultUsers.add(user.screen_name()); | ||
} | ||
} | ||
return defaultUsers.size(); | ||
} | ||
|
||
@Benchmark | ||
public int countUniqueUsersWithDefaultProfile_simdjsonPadded() { | ||
Set<String> defaultUsers = new HashSet<>(); | ||
SimdJsonTwitter twitter = simdJsonParser.parse(bufferPadded, buffer.length, SimdJsonTwitter.class); | ||
for (SimdJsonStatus status : twitter.statuses()) { | ||
SimdJsonUser user = status.user(); | ||
if (user.default_profile()) { | ||
defaultUsers.add(user.screen_name()); | ||
} | ||
} | ||
return defaultUsers.size(); | ||
} | ||
|
||
@Benchmark | ||
public int countUniqueUsersWithDefaultProfile_jackson() throws IOException { | ||
Set<String> defaultUsers = new HashSet<>(); | ||
SimdJsonTwitter twitter = objectMapper.readValue(buffer, SimdJsonTwitter.class); | ||
for (SimdJsonStatus status : twitter.statuses()) { | ||
SimdJsonUser user = status.user(); | ||
if (user.default_profile()) { | ||
defaultUsers.add(user.screen_name()); | ||
} | ||
} | ||
return defaultUsers.size(); | ||
} | ||
|
||
@Benchmark | ||
public int countUniqueUsersWithDefaultProfile_jsoniter_scala() { | ||
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_fastjson() { | ||
Set<String> defaultUsers = new HashSet<>(); | ||
SimdJsonTwitter twitter = JSON.parseObject(buffer, SimdJsonTwitter.class); | ||
for (SimdJsonStatus status : twitter.statuses()) { | ||
SimdJsonUser user = status.user(); | ||
if (user.default_profile()) { | ||
defaultUsers.add(user.screen_name()); | ||
} | ||
} | ||
return defaultUsers.size(); | ||
} | ||
|
||
record SimdJsonUser(boolean default_profile, String screen_name) { | ||
|
||
} | ||
|
||
record SimdJsonStatus(SimdJsonUser user) { | ||
|
||
} | ||
|
||
record SimdJsonTwitter(List<SimdJsonStatus> statuses) { | ||
|
||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.simdjson; | ||
|
||
import java.lang.reflect.Type; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
class ClassResolver { | ||
|
||
private final Map<Type, ResolvedClass> classCache = new HashMap<>(); | ||
|
||
ResolvedClass resolveClass(Type type) { | ||
ResolvedClass resolvedClass = classCache.get(type); | ||
if (resolvedClass != null) { | ||
return resolvedClass; | ||
} | ||
resolvedClass = new ResolvedClass(type, this); | ||
classCache.put(type, resolvedClass); | ||
return resolvedClass; | ||
} | ||
|
||
void reset() { | ||
classCache.clear(); | ||
} | ||
} |
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,4 @@ | ||
package org.simdjson; | ||
|
||
record ConstructorArgument(int idx, ResolvedClass resolvedClass) { | ||
} |
Oops, something went wrong.