Skip to content

Commit 10fc1c2

Browse files
committed
[test] JMH test for lastLevelOffset form the DLN
1 parent 54df311 commit 10fc1c2

1 file changed

Lines changed: 80 additions & 0 deletions

File tree

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Elemental
3+
* Copyright (C) 2024, Evolved Binary Ltd
4+
*
5+
* admin@evolvedbinary.com
6+
* https://www.evolvedbinary.com | https://www.elemental.xyz
7+
*
8+
* Use of this software is governed by the Business Source License 1.1
9+
* included in the LICENSE file and at www.mariadb.com/bsl11.
10+
*
11+
* Change Date: 2028-04-27
12+
*
13+
* On the date above, in accordance with the Business Source License, use
14+
* of this software will be governed by the Apache License, Version 2.0.
15+
*
16+
* Additional Use Grant: Production use of the Licensed Work for a permitted
17+
* purpose. A Permitted Purpose is any purpose other than a Competing Use.
18+
* A Competing Use means making the Software available to others in a commercial
19+
* product or service that: substitutes for the Software; substitutes for any
20+
* other product or service we offer using the Software that exists as of the
21+
* date we make the Software available; or offers the same or substantially
22+
* similar functionality as the Software.
23+
*/
24+
package org.exist.numbering;
25+
26+
import org.openjdk.jmh.annotations.Benchmark;
27+
import org.openjdk.jmh.annotations.Scope;
28+
import org.openjdk.jmh.annotations.Setup;
29+
import org.openjdk.jmh.annotations.State;
30+
import org.openjdk.jmh.infra.Blackhole;
31+
32+
/**
33+
* Benchmarks for {@link DLNBase#lastLevelOffset()}.
34+
*
35+
* @author <a href="mailto:adam@evolvedbinary.com">Adam Retter</a>
36+
*/
37+
@State(Scope.Benchmark)
38+
public class LastLevelOffsetBenchmark {
39+
40+
private DLN shallowDln; // eg 1
41+
42+
private DLN wideDln; // eg 1.500
43+
44+
private DLN deepDln; // eg 1.1.1.1.1.1.1.1.1.1
45+
46+
@Setup
47+
public void setup() {
48+
shallowDln = new DLN(1);
49+
50+
wideDln = new DLN(1);
51+
wideDln.addLevelId(500, false);
52+
53+
deepDln = new DLN(1);
54+
for (int i = 0; i < 9; i++) {
55+
deepDln.addLevelId(1, false);
56+
}
57+
58+
}
59+
60+
@Benchmark
61+
public void lastLevelOffset_shallow(final Blackhole bh) {
62+
bh.consume(shallowDln.lastLevelOffset());
63+
}
64+
65+
@Benchmark
66+
public void lastLevelOffset_deep(final Blackhole bh) {
67+
bh.consume(deepDln.lastLevelOffset());
68+
}
69+
70+
@Benchmark
71+
public void lastLevelOffset_wide(final Blackhole bh) {
72+
bh.consume(wideDln.lastLevelOffset());
73+
}
74+
75+
public static void main(final String[] args) {
76+
final LastLevelOffsetBenchmark bench = new LastLevelOffsetBenchmark();
77+
bench.setup();
78+
79+
}
80+
}

0 commit comments

Comments
 (0)