-
-
Save theigl/0fe8811f7f0ed964a5a1bbbc34fb0cd8 to your computer and use it in GitHub Desktop.
Wicket Component Benchmars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.apache.wicket; | |
import org.apache.wicket.markup.html.WebMarkupContainer; | |
import org.apache.wicket.mock.MockApplication; | |
import org.apache.wicket.mock.MockWebRequest; | |
import org.apache.wicket.model.Model; | |
import org.apache.wicket.protocol.http.WebSession; | |
import org.apache.wicket.protocol.http.mock.MockServletContext; | |
import org.apache.wicket.request.Url; | |
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.Warmup; | |
import java.util.stream.IntStream; | |
public class ComponentBenchmarks { | |
private static final int WARMUPS = 10; | |
private static final int ITERATIONS = 10; | |
@State(Scope.Benchmark) | |
public static class ExecutionPlan { | |
private MarkupContainer component0; | |
private MarkupContainer component1; | |
private MarkupContainer component2; | |
private MarkupContainer component3; | |
private MarkupContainer component4; | |
private MarkupContainer component5; | |
private MarkupContainer component6; | |
@Setup(Level.Trial) | |
public void setUp() { | |
final MockApplication app = new MockApplication(); | |
app.setServletContext(new MockServletContext(app, null)); | |
ThreadContext.setApplication(app); | |
app.setName(getClass().getName()); | |
app.initApplication(); | |
final Session session = new WebSession(new MockWebRequest(Url.parse("/"))); | |
ThreadContext.setSession(session); | |
ThreadContext.setApplication(app); | |
component0 = new WebMarkupContainer("anyId"); | |
component0.setMarkupId("anyId"); | |
component0.setOutputMarkupId(true); | |
IntStream.range(0, 50).forEach(i -> component0.add(newChild(i, 50, false, false, false))); | |
component1 = new WebMarkupContainer("anyId"); | |
component1.setMarkupId("anyId"); | |
component1.setOutputMarkupId(true); | |
IntStream.range(0, 50).forEach(i -> component1.add(newChild(i, 50, true, false, false))); | |
component2 = new WebMarkupContainer("anyId"); | |
component2.setMarkupId("anyId"); | |
component2.setOutputMarkupId(true); | |
IntStream.range(0, 50).forEach(i -> component2.add(newChild(i, 50, false, false, false))); | |
component3 = new WebMarkupContainer("anyId"); | |
component3.setMarkupId("anyId"); | |
component3.setOutputMarkupId(true); | |
IntStream.range(0, 50).forEach(i -> component3.add(newChild(i, 50, true, true, false))); | |
component4 = new WebMarkupContainer("anyId"); | |
component4.setMarkupId("anyId"); | |
component4.setOutputMarkupId(true); | |
IntStream.range(0, 50).forEach(i -> component4.add(newChild(i, 50, false, false, true))); | |
component5 = new WebMarkupContainer("anyId"); | |
component5.setMarkupId("anyId"); | |
component5.setOutputMarkupId(true); | |
IntStream.range(0, 50).forEach(i -> component5.add(newChild(i, 50, true, false, true))); | |
component6 = new WebMarkupContainer("anyId"); | |
component6.setMarkupId("anyId"); | |
component6.setOutputMarkupId(true); | |
IntStream.range(0, 50).forEach(i -> component6.add(newChild(i, 50, true, true, true))); | |
} | |
private Component newChild(int index, int maxChildren, boolean withModel, boolean withBehavior, boolean withMetaData) { | |
final WebMarkupContainer c = createChild(index, withModel, false, withMetaData); | |
IntStream.range(0, maxChildren).forEach(i -> c.add(createChild(i, withModel, withBehavior, withMetaData))); | |
return c; | |
} | |
private WebMarkupContainer createChild(int index, boolean withModel, boolean withBehavior, boolean withMetaData) { | |
final WebMarkupContainer c = new WebMarkupContainer("anyChildId" + index); | |
if (withMetaData) { | |
c.setMarkupId("anyChild" + index); | |
} | |
if (withModel) { | |
c.setDefaultModel(Model.of(index)); | |
} | |
if (withBehavior) { | |
c.add(AttributeModifier.replace("test", "test")); | |
} | |
return c; | |
} | |
} | |
@Fork(value = 1, warmups = 1) | |
@Benchmark | |
@BenchmarkMode(Mode.Throughput) | |
@Warmup(iterations = WARMUPS) | |
@Measurement(iterations = ITERATIONS) | |
public void detachComponent(ExecutionPlan plan) { | |
plan.component0.detach(); | |
} | |
@Fork(value = 1, warmups = 1) | |
@Benchmark | |
@BenchmarkMode(Mode.Throughput) | |
@Warmup(iterations = WARMUPS) | |
@Measurement(iterations = ITERATIONS) | |
public void detachComponentWithModel(ExecutionPlan plan) { | |
plan.component1.detach(); | |
} | |
@Fork(value = 1, warmups = 1) | |
@Benchmark | |
@BenchmarkMode(Mode.Throughput) | |
@Warmup(iterations = WARMUPS) | |
@Measurement(iterations = ITERATIONS) | |
public void detachComponentWithBehavior(ExecutionPlan plan) { | |
plan.component2.detach(); | |
} | |
@Fork(value = 1, warmups = 1) | |
@Benchmark | |
@BenchmarkMode(Mode.Throughput) | |
@Warmup(iterations = WARMUPS) | |
@Measurement(iterations = ITERATIONS) | |
public void detachComponentWithModelAndBehavior(ExecutionPlan plan) { | |
plan.component3.detach(); | |
} | |
@Fork(value = 1, warmups = 1) | |
@Benchmark | |
@BenchmarkMode(Mode.Throughput) | |
@Warmup(iterations = WARMUPS) | |
@Measurement(iterations = ITERATIONS) | |
public void detachComponentWithMetaData(ExecutionPlan plan) { | |
plan.component4.detach(); | |
} | |
@Fork(value = 1, warmups = 1) | |
@Benchmark | |
@BenchmarkMode(Mode.Throughput) | |
@Warmup(iterations = WARMUPS) | |
@Measurement(iterations = ITERATIONS) | |
public void detachComponentWithMetaDataAndModel(ExecutionPlan plan) { | |
plan.component5.detach(); | |
} | |
@Fork(value = 1, warmups = 1) | |
@Benchmark | |
@BenchmarkMode(Mode.Throughput) | |
@Warmup(iterations = WARMUPS) | |
@Measurement(iterations = ITERATIONS) | |
public void detachComponentWithMetaDataModelAndBehavior(ExecutionPlan plan) { | |
plan.component6.detach(); | |
} | |
public static void main(String[] args) throws Exception { | |
org.openjdk.jmh.Main.main(args); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment