|
| 1 | +package com.apicatalog.jsonld.benchmark; |
| 2 | + |
| 3 | +import com.apicatalog.jsonld.JsonLdError; |
| 4 | +import com.apicatalog.jsonld.api.ToRdfApi; |
| 5 | +import com.apicatalog.jsonld.document.Document; |
| 6 | +import com.apicatalog.jsonld.loader.DocumentLoaderOptions; |
| 7 | +import com.apicatalog.jsonld.loader.FileLoader; |
| 8 | +import com.apicatalog.rdf.RdfDataset; |
| 9 | +import org.openjdk.jmh.annotations.Benchmark; |
| 10 | +import org.openjdk.jmh.annotations.BenchmarkMode; |
| 11 | +import org.openjdk.jmh.annotations.Fork; |
| 12 | +import org.openjdk.jmh.annotations.Level; |
| 13 | +import org.openjdk.jmh.annotations.Measurement; |
| 14 | +import org.openjdk.jmh.annotations.Mode; |
| 15 | +import org.openjdk.jmh.annotations.OutputTimeUnit; |
| 16 | +import org.openjdk.jmh.annotations.Scope; |
| 17 | +import org.openjdk.jmh.annotations.Setup; |
| 18 | +import org.openjdk.jmh.annotations.State; |
| 19 | +import org.openjdk.jmh.annotations.Warmup; |
| 20 | + |
| 21 | +import java.net.URISyntaxException; |
| 22 | +import java.net.URL; |
| 23 | +import java.util.concurrent.TimeUnit; |
| 24 | + |
| 25 | +@State(Scope.Benchmark) |
| 26 | +@Warmup(iterations = 0) |
| 27 | +@BenchmarkMode({Mode.AverageTime}) |
| 28 | +@Fork(value = 1, jvmArgs = {"-Xms16G", "-Xmx16G", "-XX:+UnlockExperimentalVMOptions", "-XX:+UseEpsilonGC", |
| 29 | + "-XX:+AlwaysPreTouch"}) |
| 30 | +@Measurement(iterations = 99999999, time = 1, timeUnit = TimeUnit.MILLISECONDS) |
| 31 | +@OutputTimeUnit(TimeUnit.MILLISECONDS) |
| 32 | +/* |
| 33 | + * This benchmark is used to test how many iterations we can run before running out of memory. |
| 34 | + */ |
| 35 | +public class OOMBenchmark { |
| 36 | + |
| 37 | + Document document; |
| 38 | + |
| 39 | + @Setup(Level.Invocation) |
| 40 | + public void setUp() throws URISyntaxException, JsonLdError { |
| 41 | + document = null; |
| 42 | + URL fileUrl = getClass().getClassLoader().getResource("benchmark/datagovbe-valid.jsonld"); |
| 43 | + document = (new FileLoader()).loadDocument(fileUrl.toURI(), new DocumentLoaderOptions()); |
| 44 | + } |
| 45 | + |
| 46 | + @Benchmark |
| 47 | + public int toRdfApiGet() throws JsonLdError { |
| 48 | + RdfDataset rdfDataset = new ToRdfApi(document).get(); |
| 49 | + return rdfDataset.size(); |
| 50 | + } |
| 51 | + |
| 52 | +} |
0 commit comments