Skip to content

Commit

Permalink
Use @param instead of a naming convention on the state class
Browse files Browse the repository at this point in the history
  • Loading branch information
dsyer committed Sep 4, 2017
1 parent 5a2e68d commit d4de7e7
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 208 deletions.
200 changes: 0 additions & 200 deletions static/src/main/java/com/example/bench/DemoBenchmark.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,6 @@ private String file(String path) {
}

public void before() throws Exception {
String name = getClass().getSimpleName().contains("_")
? getClass().getSimpleName().split("_")[1] : "";
if (name.length() == 4) {
setProfiles(name.toLowerCase());
}
else {
setProfiles();
}
args.set(this.classpath, getClasspath());
}

Expand Down
73 changes: 73 additions & 0 deletions static/src/main/java/com/example/bench/SampleBenchmark.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright 2016-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.bench;

import com.example.demo.DemoApplication;

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.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.annotations.Warmup;

@Measurement(iterations = 5)
@Warmup(iterations = 1)
@Fork(value = 2, warmups = 0)
@BenchmarkMode(Mode.AverageTime)
public class SampleBenchmark {

@Benchmark
public void main(ApplicationState state) throws Exception {
state.setMainClass(DemoApplication.class.getName());
state.run();
}

@State(Scope.Benchmark)
public static class ApplicationState extends ProcessLauncherState {

public static enum Sample {
empt, demo, actr, jdbc, actj, jpae, conf, erka, busr, zuul, erkb, slth;
}

@Param
private Sample sample = Sample.demo;

public ApplicationState() {
super("target", "--server.port=0");
}

@TearDown(Level.Iteration)
public void stop() throws Exception {
super.after();
}

@Setup(Level.Trial)
public void start() throws Exception {
if (sample!=Sample.demo) {
setProfiles(sample.toString());
}
super.before();
}
}

}
83 changes: 83 additions & 0 deletions static/src/main/java/com/example/bench/SlimBenchmark.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright 2016-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.bench;

import com.example.func.FuncApplication;
import com.example.lite.LiteApplication;
import com.example.slim.SlimApplication;
import com.example.thin.ThinApplication;

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.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.annotations.Warmup;

@Measurement(iterations = 5)
@Warmup(iterations = 1)
@Fork(value = 2, warmups = 0)
@BenchmarkMode(Mode.AverageTime)
public class SlimBenchmark {

@Benchmark
public void slim(ApplicationState state) throws Exception {
state.setMainClass(SlimApplication.class.getName());
state.run();
}

@Benchmark
public void thin(ApplicationState state) throws Exception {
state.setMainClass(ThinApplication.class.getName());
state.run();
}

@Benchmark
public void lite(ApplicationState state) throws Exception {
state.setMainClass(LiteApplication.class.getName());
state.run();
}

@Benchmark
public void func(ApplicationState state) throws Exception {
state.setMainClass(FuncApplication.class.getName());
state.run();
}

@State(Scope.Benchmark)
public static class ApplicationState extends ProcessLauncherState {

public ApplicationState() {
super("target", "--server.port=0");
}

@TearDown(Level.Iteration)
public void stop() throws Exception {
super.after();
}

@Setup(Level.Trial)
public void start() throws Exception {
super.before();
}
}

}

0 comments on commit d4de7e7

Please sign in to comment.