forked from joel-jeremy/java-config-library-benchmarks
/
Benchmarks.java
49 lines (40 loc) · 1.47 KB
/
Benchmarks.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package io.github.joeljeremy7.java.config.lib.benchmarks;
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.util.Properties;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
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.util.concurrent.TimeUnit;
public abstract class Benchmarks {
@State(Scope.Benchmark)
public static class BenchmarkState {
private ImmutableConfig config;
@Setup
public void setup() throws IOException, URISyntaxException {
final InputStream inStream = Benchmark.class.getResourceAsStream("/AppProps.properties");
final Properties props= new Properties();
props.load(inStream);
this.config= ImmutableConfig.from(props);
}
}
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public static class Avgt extends Benchmarks {}
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public static class Thrpt extends Benchmarks {}
@Benchmark
public String Coat_String(BenchmarkState state) {
return state.config.test1();
}
@Benchmark
public int Coat_Int(BenchmarkState state) {
return state.config.testInt1();
}
}