-
-
Notifications
You must be signed in to change notification settings - Fork 33
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
f0a54f6
commit 5c53ad2
Showing
31 changed files
with
1,837,852 additions
and
0 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
107 changes: 107 additions & 0 deletions
107
src/test/java/com/apicatalog/jsonld/benchmark/BasicProcessingAlgorithmsBenchmark.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,107 @@ | ||
package com.apicatalog.jsonld.benchmark; | ||
|
||
import com.apicatalog.jsonld.JsonLd; | ||
import com.apicatalog.jsonld.JsonLdError; | ||
import com.apicatalog.jsonld.api.ExpansionApi; | ||
import com.apicatalog.jsonld.api.FlatteningApi; | ||
import com.apicatalog.jsonld.document.Document; | ||
import com.apicatalog.jsonld.document.JsonDocument; | ||
import com.apicatalog.jsonld.loader.DocumentLoaderOptions; | ||
import com.apicatalog.jsonld.loader.FileLoader; | ||
import jakarta.json.JsonArray; | ||
import jakarta.json.JsonObject; | ||
import jakarta.json.JsonStructure; | ||
import jakarta.json.JsonValue; | ||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.BenchmarkMode; | ||
import org.openjdk.jmh.annotations.Fork; | ||
import org.openjdk.jmh.annotations.Level; | ||
import org.openjdk.jmh.annotations.Measurement; | ||
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 org.openjdk.jmh.annotations.Warmup; | ||
import org.openjdk.jmh.runner.Runner; | ||
import org.openjdk.jmh.runner.RunnerException; | ||
import org.openjdk.jmh.runner.options.Options; | ||
import org.openjdk.jmh.runner.options.OptionsBuilder; | ||
|
||
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* This benchmark is used to compare the performance of the main processing algorithms of JSON-LD. | ||
*/ | ||
@State(Scope.Benchmark) | ||
@Warmup(iterations = 5) | ||
@BenchmarkMode({Mode.AverageTime}) | ||
@Fork(value = 1, jvmArgs = {"-Xmx2048M", "-Xms2048M"}) | ||
@Measurement(iterations = 5) | ||
@OutputTimeUnit(TimeUnit.MILLISECONDS) | ||
public class BasicProcessingAlgorithmsBenchmark { | ||
|
||
private Document datagovbeDcat; | ||
private Document datagovbeDcatContext; | ||
private Document datagovbeDcatCompact; | ||
private Document datagovbeDcatFlatten; | ||
|
||
@Setup(Level.Invocation) | ||
public void setUp() throws URISyntaxException, JsonLdError { | ||
datagovbeDcat = loadDocument("benchmark/datagovbe/dcat.jsonld"); | ||
datagovbeDcatCompact = loadDocument("benchmark/datagovbe/dcat-compact.jsonld"); | ||
datagovbeDcatFlatten = loadDocument("benchmark/datagovbe/dcat-flatten.jsonld"); | ||
datagovbeDcatContext = loadDocument("benchmark/datagovbe/context/context.jsonld"); | ||
} | ||
|
||
public static void main(String[] args) throws RunnerException { | ||
|
||
// The classe(s) that are included may not get compiled by your IDE. | ||
// Run `mvn clean verify -DskipTests` before running the benchmarks. | ||
|
||
Options opt = new OptionsBuilder() | ||
.include(BasicProcessingAlgorithmsBenchmark.class.getName()+".*") | ||
.build(); | ||
|
||
new Runner(opt).run(); | ||
} | ||
|
||
@Benchmark | ||
public JsonObject compactDatagovbeDcat() throws JsonLdError { | ||
return JsonLd.compact(datagovbeDcat, datagovbeDcatContext).get(); | ||
} | ||
|
||
@Benchmark | ||
public JsonObject compactDatagovbeDcatEmptyContext() throws JsonLdError { | ||
return JsonLd.compact(datagovbeDcat, JsonDocument.of(JsonValue.EMPTY_JSON_OBJECT)).get(); | ||
} | ||
|
||
@Benchmark | ||
public JsonArray expandDatagovbeDcatFromCompact() throws JsonLdError { | ||
return new ExpansionApi(datagovbeDcatCompact).context(datagovbeDcatContext.getJsonContent().get()).get(); | ||
} | ||
|
||
@Benchmark | ||
public JsonArray expandDatagovbeDcatFromFlatten() throws JsonLdError { | ||
return JsonLd.expand(datagovbeDcatFlatten).get(); | ||
} | ||
|
||
@Benchmark | ||
public JsonStructure flattenDatagovbeDcat() throws JsonLdError { | ||
return JsonLd.flatten(datagovbeDcat).get(); | ||
} | ||
|
||
@Benchmark | ||
public JsonStructure flattenDatagovbeDcatFromCompact() throws JsonLdError { | ||
return new FlatteningApi(datagovbeDcatCompact).context(datagovbeDcatContext.getJsonContent().get()).get(); | ||
} | ||
|
||
private Document loadDocument(String name) throws JsonLdError, URISyntaxException { | ||
URL fileUrl = getClass().getClassLoader().getResource(name); | ||
Document document = (new FileLoader()).loadDocument(fileUrl.toURI(), new DocumentLoaderOptions()); | ||
return document; | ||
} | ||
|
||
} |
68 changes: 68 additions & 0 deletions
68
src/test/java/com/apicatalog/jsonld/benchmark/OOMBenchmark.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,68 @@ | ||
package com.apicatalog.jsonld.benchmark; | ||
|
||
import com.apicatalog.jsonld.JsonLdError; | ||
import com.apicatalog.jsonld.api.ToRdfApi; | ||
import com.apicatalog.jsonld.document.Document; | ||
import com.apicatalog.jsonld.loader.DocumentLoaderOptions; | ||
import com.apicatalog.jsonld.loader.FileLoader; | ||
import com.apicatalog.rdf.RdfDataset; | ||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.BenchmarkMode; | ||
import org.openjdk.jmh.annotations.Fork; | ||
import org.openjdk.jmh.annotations.Level; | ||
import org.openjdk.jmh.annotations.Measurement; | ||
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 org.openjdk.jmh.annotations.Warmup; | ||
import org.openjdk.jmh.runner.Runner; | ||
import org.openjdk.jmh.runner.RunnerException; | ||
import org.openjdk.jmh.runner.options.Options; | ||
import org.openjdk.jmh.runner.options.OptionsBuilder; | ||
|
||
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
@State(Scope.Benchmark) | ||
@Warmup(iterations = 0) | ||
@BenchmarkMode({Mode.AverageTime}) | ||
@Fork(value = 1, jvmArgs = {"-Xms16G", "-Xmx16G", "-XX:+UnlockExperimentalVMOptions", "-XX:+UseEpsilonGC", | ||
"-XX:+AlwaysPreTouch"}) | ||
@Measurement(iterations = 99999999, time = 1, timeUnit = TimeUnit.MILLISECONDS) | ||
@OutputTimeUnit(TimeUnit.MILLISECONDS) | ||
/* | ||
* This benchmark is used to test how many iterations we can run before running out of memory. | ||
*/ | ||
public class OOMBenchmark { | ||
|
||
private Document datagovbeDcat; | ||
|
||
@Setup(Level.Invocation) | ||
public void setUp() throws URISyntaxException, JsonLdError { | ||
datagovbeDcat = null; | ||
URL fileUrl = getClass().getClassLoader().getResource("benchmark/datagovbe/dcat.jsonld"); | ||
datagovbeDcat = (new FileLoader()).loadDocument(fileUrl.toURI(), new DocumentLoaderOptions()); | ||
} | ||
|
||
public static void main(String[] args) throws RunnerException { | ||
|
||
// The classe(s) that are included may not get compiled by your IDE. | ||
// Run `mvn clean verify -DskipTests` before running the benchmarks. | ||
|
||
Options opt = new OptionsBuilder() | ||
.include(OOMBenchmark.class.getName()+".*") | ||
.build(); | ||
|
||
new Runner(opt).run(); | ||
} | ||
|
||
@Benchmark | ||
public int datagovbeDcatToRdf() throws JsonLdError { | ||
RdfDataset rdfDataset = new ToRdfApi(datagovbeDcat).get(); | ||
return rdfDataset.size(); | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
src/test/java/com/apicatalog/jsonld/benchmark/RunAllBenchmarks.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,21 @@ | ||
package com.apicatalog.jsonld.benchmark; | ||
|
||
import org.openjdk.jmh.runner.Runner; | ||
import org.openjdk.jmh.runner.RunnerException; | ||
import org.openjdk.jmh.runner.options.Options; | ||
import org.openjdk.jmh.runner.options.OptionsBuilder; | ||
|
||
public class RunAllBenchmarks { | ||
|
||
public static void main(String[] args) throws RunnerException { | ||
|
||
// The classe(s) that are included may not get compiled by your IDE. | ||
// Run `mvn clean verify -DskipTests` before running the benchmarks. | ||
|
||
Options opt = new OptionsBuilder() | ||
.include("com.apicatalog.jsonld.benchmark.*.*") | ||
.build(); | ||
|
||
new Runner(opt).run(); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
src/test/java/com/apicatalog/jsonld/benchmark/ToRdfLargeFilesBenchmark.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,62 @@ | ||
package com.apicatalog.jsonld.benchmark; | ||
|
||
import com.apicatalog.jsonld.JsonLdError; | ||
import com.apicatalog.jsonld.api.ToRdfApi; | ||
import com.apicatalog.jsonld.document.Document; | ||
import com.apicatalog.jsonld.loader.DocumentLoaderOptions; | ||
import com.apicatalog.jsonld.loader.FileLoader; | ||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.BenchmarkMode; | ||
import org.openjdk.jmh.annotations.Fork; | ||
import org.openjdk.jmh.annotations.Level; | ||
import org.openjdk.jmh.annotations.Measurement; | ||
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 org.openjdk.jmh.annotations.Warmup; | ||
import org.openjdk.jmh.runner.Runner; | ||
import org.openjdk.jmh.runner.RunnerException; | ||
import org.openjdk.jmh.runner.options.Options; | ||
import org.openjdk.jmh.runner.options.OptionsBuilder; | ||
|
||
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
@State(Scope.Benchmark) | ||
@Warmup(iterations = 5) | ||
@BenchmarkMode({Mode.AverageTime}) | ||
@Fork(value = 1, jvmArgs = {"-Xmx1024M", "-Xms1024M"}) | ||
@Measurement(iterations = 5) | ||
@OutputTimeUnit(TimeUnit.MILLISECONDS) | ||
public class ToRdfLargeFilesBenchmark { | ||
|
||
private Document datagovbeDcat; | ||
|
||
@Setup(Level.Invocation) | ||
public void setUp() throws URISyntaxException, JsonLdError { | ||
URL fileUrl = getClass().getClassLoader().getResource("benchmark/datagovbe/dcat.jsonld"); | ||
|
||
datagovbeDcat = (new FileLoader()).loadDocument(fileUrl.toURI(), new DocumentLoaderOptions()); | ||
} | ||
|
||
public static void main(String[] args) throws RunnerException { | ||
|
||
// The classe(s) that are included may not get compiled by your IDE. | ||
// Run `mvn clean verify -DskipTests` before running the benchmarks. | ||
|
||
Options opt = new OptionsBuilder() | ||
.include(ToRdfLargeFilesBenchmark.class.getName()+".*") | ||
.build(); | ||
|
||
new Runner(opt).run(); | ||
} | ||
|
||
@Benchmark | ||
public Object datagovbeDcat() throws JsonLdError { | ||
return new ToRdfApi(datagovbeDcat).get(); | ||
} | ||
|
||
} |
Oops, something went wrong.