Skip to content

Commit 6f8f8d8

Browse files
committed
GH-3654 add benchmarks
1 parent c39f32a commit 6f8f8d8

File tree

4 files changed

+216
-0
lines changed

4 files changed

+216
-0
lines changed

core/rio/jsonld/pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,17 @@
7878
<version>${project.version}</version>
7979
<scope>test</scope>
8080
</dependency>
81+
<dependency>
82+
<groupId>org.openjdk.jmh</groupId>
83+
<artifactId>jmh-core</artifactId>
84+
<version>${jmhVersion}</version>
85+
<scope>test</scope>
86+
</dependency>
87+
<dependency>
88+
<groupId>org.openjdk.jmh</groupId>
89+
<artifactId>jmh-generator-annprocess</artifactId>
90+
<version>${jmhVersion}</version>
91+
<scope>test</scope>
92+
</dependency>
8193
</dependencies>
8294
</project>
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 Eclipse RDF4J contributors.
3+
*
4+
* All rights reserved. This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Distribution License v1.0
6+
* which accompanies this distribution, and is available at
7+
* http://www.eclipse.org/org/documents/edl-v10.php.
8+
*
9+
* SPDX-License-Identifier: BSD-3-Clause
10+
******************************************************************************/
11+
12+
package org.eclipse.rdf4j.rio.jsonld;
13+
14+
import java.io.BufferedWriter;
15+
import java.io.File;
16+
import java.io.IOException;
17+
import java.io.InputStream;
18+
import java.io.StringReader;
19+
import java.io.StringWriter;
20+
import java.io.Writer;
21+
import java.nio.charset.StandardCharsets;
22+
import java.util.concurrent.TimeUnit;
23+
24+
import org.apache.commons.io.FileUtils;
25+
import org.eclipse.rdf4j.model.Model;
26+
import org.eclipse.rdf4j.rio.RDFFormat;
27+
import org.eclipse.rdf4j.rio.Rio;
28+
import org.eclipse.rdf4j.rio.WriterConfig;
29+
import org.eclipse.rdf4j.rio.helpers.BasicWriterSettings;
30+
import org.openjdk.jmh.annotations.Benchmark;
31+
import org.openjdk.jmh.annotations.BenchmarkMode;
32+
import org.openjdk.jmh.annotations.Fork;
33+
import org.openjdk.jmh.annotations.Level;
34+
import org.openjdk.jmh.annotations.Measurement;
35+
import org.openjdk.jmh.annotations.Mode;
36+
import org.openjdk.jmh.annotations.OutputTimeUnit;
37+
import org.openjdk.jmh.annotations.Scope;
38+
import org.openjdk.jmh.annotations.Setup;
39+
import org.openjdk.jmh.annotations.State;
40+
import org.openjdk.jmh.annotations.Warmup;
41+
42+
@State(Scope.Benchmark)
43+
@Warmup(iterations = 5)
44+
@BenchmarkMode({ Mode.AverageTime })
45+
@Fork(value = 1, jvmArgs = { "-Xms2G", "-Xmx2G" })
46+
//@Fork(value = 1, jvmArgs = {"-Xms2G", "-Xmx2G", "-XX:StartFlightRecording=delay=5s,duration=120s,filename=recording.jfr,settings=profile", "-XX:FlightRecorderOptions=samplethreads=true,stackdepth=1024", "-XX:+UnlockDiagnosticVMOptions", "-XX:+DebugNonSafepoints"})
47+
@Measurement(iterations = 5)
48+
@OutputTimeUnit(TimeUnit.MILLISECONDS)
49+
public class ReadWriteBenchmark {
50+
51+
Model parsed;
52+
private String parsedAsString;
53+
54+
@Setup(Level.Trial)
55+
public void setUp() throws IOException {
56+
try (InputStream resourceAsStream = ReadWriteBenchmark.class.getClassLoader()
57+
.getResourceAsStream("benchmark/datagovbe-valid.jsonld")) {
58+
parsed = Rio.parse(resourceAsStream, "", RDFFormat.JSONLD);
59+
}
60+
61+
parsedAsString = FileUtils.readFileToString(new File(
62+
ReadWriteBenchmark.class.getClassLoader().getResource("benchmark/datagovbe-valid.jsonld").getFile()),
63+
StandardCharsets.UTF_8);
64+
}
65+
66+
@Benchmark
67+
public Writer writeToStringWriter() throws IOException {
68+
try (Writer writer = new StringWriter()) {
69+
Rio.write(parsed, writer, RDFFormat.JSONLD,
70+
new WriterConfig().set(BasicWriterSettings.PRETTY_PRINT, false));
71+
return writer;
72+
}
73+
}
74+
75+
@Benchmark
76+
public Model parseFromString() throws IOException {
77+
return Rio.parse(new StringReader(parsedAsString), "", RDFFormat.JSONLD);
78+
}
79+
80+
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
Applies to: datagovbe-valid.ttl
2+
3+
File is based on (with modifications): https://github.com/Fedict/dcat/blob/master/all/datagovbe.nt.gz
4+
5+
CC0 1.0 and potentially CC-BY-2.0
6+
7+
----------------------------------------
8+
CC0 1.0 Universal
9+
10+
Statement of Purpose
11+
12+
The laws of most jurisdictions throughout the world automatically confer
13+
exclusive Copyright and Related Rights (defined below) upon the creator and
14+
subsequent owner(s) (each and all, an "owner") of an original work of
15+
authorship and/or a database (each, a "Work").
16+
17+
Certain owners wish to permanently relinquish those rights to a Work for the
18+
purpose of contributing to a commons of creative, cultural and scientific
19+
works ("Commons") that the public can reliably and without fear of later
20+
claims of infringement build upon, modify, incorporate in other works, reuse
21+
and redistribute as freely as possible in any form whatsoever and for any
22+
purposes, including without limitation commercial purposes. These owners may
23+
contribute to the Commons to promote the ideal of a free culture and the
24+
further production of creative, cultural and scientific works, or to gain
25+
reputation or greater distribution for their Work in part through the use and
26+
efforts of others.
27+
28+
For these and/or other purposes and motivations, and without any expectation
29+
of additional consideration or compensation, the person associating CC0 with a
30+
Work (the "Affirmer"), to the extent that he or she is an owner of Copyright
31+
and Related Rights in the Work, voluntarily elects to apply CC0 to the Work
32+
and publicly distribute the Work under its terms, with knowledge of his or her
33+
Copyright and Related Rights in the Work and the meaning and intended legal
34+
effect of CC0 on those rights.
35+
36+
1. Copyright and Related Rights. A Work made available under CC0 may be
37+
protected by copyright and related or neighboring rights ("Copyright and
38+
Related Rights"). Copyright and Related Rights include, but are not limited
39+
to, the following:
40+
41+
i. the right to reproduce, adapt, distribute, perform, display, communicate,
42+
and translate a Work;
43+
44+
ii. moral rights retained by the original author(s) and/or performer(s);
45+
46+
iii. publicity and privacy rights pertaining to a person's image or likeness
47+
depicted in a Work;
48+
49+
iv. rights protecting against unfair competition in regards to a Work,
50+
subject to the limitations in paragraph 4(a), below;
51+
52+
v. rights protecting the extraction, dissemination, use and reuse of data in
53+
a Work;
54+
55+
vi. database rights (such as those arising under Directive 96/9/EC of the
56+
European Parliament and of the Council of 11 March 1996 on the legal
57+
protection of databases, and under any national implementation thereof,
58+
including any amended or successor version of such directive); and
59+
60+
vii. other similar, equivalent or corresponding rights throughout the world
61+
based on applicable law or treaty, and any national implementations thereof.
62+
63+
2. Waiver. To the greatest extent permitted by, but not in contravention of,
64+
applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and
65+
unconditionally waives, abandons, and surrenders all of Affirmer's Copyright
66+
and Related Rights and associated claims and causes of action, whether now
67+
known or unknown (including existing as well as future claims and causes of
68+
action), in the Work (i) in all territories worldwide, (ii) for the maximum
69+
duration provided by applicable law or treaty (including future time
70+
extensions), (iii) in any current or future medium and for any number of
71+
copies, and (iv) for any purpose whatsoever, including without limitation
72+
commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes
73+
the Waiver for the benefit of each member of the public at large and to the
74+
detriment of Affirmer's heirs and successors, fully intending that such Waiver
75+
shall not be subject to revocation, rescission, cancellation, termination, or
76+
any other legal or equitable action to disrupt the quiet enjoyment of the Work
77+
by the public as contemplated by Affirmer's express Statement of Purpose.
78+
79+
3. Public License Fallback. Should any part of the Waiver for any reason be
80+
judged legally invalid or ineffective under applicable law, then the Waiver
81+
shall be preserved to the maximum extent permitted taking into account
82+
Affirmer's express Statement of Purpose. In addition, to the extent the Waiver
83+
is so judged Affirmer hereby grants to each affected person a royalty-free,
84+
non transferable, non sublicensable, non exclusive, irrevocable and
85+
unconditional license to exercise Affirmer's Copyright and Related Rights in
86+
the Work (i) in all territories worldwide, (ii) for the maximum duration
87+
provided by applicable law or treaty (including future time extensions), (iii)
88+
in any current or future medium and for any number of copies, and (iv) for any
89+
purpose whatsoever, including without limitation commercial, advertising or
90+
promotional purposes (the "License"). The License shall be deemed effective as
91+
of the date CC0 was applied by Affirmer to the Work. Should any part of the
92+
License for any reason be judged legally invalid or ineffective under
93+
applicable law, such partial invalidity or ineffectiveness shall not
94+
invalidate the remainder of the License, and in such case Affirmer hereby
95+
affirms that he or she will not (i) exercise any of his or her remaining
96+
Copyright and Related Rights in the Work or (ii) assert any associated claims
97+
and causes of action with respect to the Work, in either case contrary to
98+
Affirmer's express Statement of Purpose.
99+
100+
4. Limitations and Disclaimers.
101+
102+
a. No trademark or patent rights held by Affirmer are waived, abandoned,
103+
surrendered, licensed or otherwise affected by this document.
104+
105+
b. Affirmer offers the Work as-is and makes no representations or warranties
106+
of any kind concerning the Work, express, implied, statutory or otherwise,
107+
including without limitation warranties of title, merchantability, fitness
108+
for a particular purpose, non infringement, or the absence of latent or
109+
other defects, accuracy, or the present or absence of errors, whether or not
110+
discoverable, all to the greatest extent permissible under applicable law.
111+
112+
c. Affirmer disclaims responsibility for clearing rights of other persons
113+
that may apply to the Work or any use thereof, including without limitation
114+
any person's Copyright and Related Rights in the Work. Further, Affirmer
115+
disclaims responsibility for obtaining any necessary consents, permissions
116+
or other rights required for any use of the Work.
117+
118+
d. Affirmer understands and acknowledges that Creative Commons is not a
119+
party to this document and has no duty or obligation with respect to this
120+
CC0 or use of the Work.
121+
122+
For more information, please see
123+
<http://creativecommons.org/publicdomain/zero/1.0/>

core/rio/jsonld/src/test/resources/benchmark/datagovbe-valid.jsonld

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)