This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-performance-tests.git
The following commit(s) were added to refs/heads/main by this push:
new 673ac89 (chores) performance: add new test to evaluate the cost of
creating certain core objects
673ac89 is described below
commit 673ac891681df5eddd631bf89f4d01b38c937d98
Author: Otavio Rodolfo Piske <[email protected]>
AuthorDate: Thu May 11 17:51:47 2023 +0200
(chores) performance: add new test to evaluate the cost of creating certain
core objects
---
.../camel/itest/jmh/CoreObjectsCreationTest.java | 77 ++++++++++++++++++++++
1 file changed, 77 insertions(+)
diff --git
a/tests/camel-jmh/src/test/java/org/apache/camel/itest/jmh/CoreObjectsCreationTest.java
b/tests/camel-jmh/src/test/java/org/apache/camel/itest/jmh/CoreObjectsCreationTest.java
new file mode 100644
index 0000000..8f93e3d
--- /dev/null
+++
b/tests/camel-jmh/src/test/java/org/apache/camel/itest/jmh/CoreObjectsCreationTest.java
@@ -0,0 +1,77 @@
+package org.apache.camel.itest.jmh;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.support.DefaultExchange;
+import org.apache.camel.support.DefaultMessage;
+import org.junit.jupiter.api.Test;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Level;
+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 org.openjdk.jmh.infra.Blackhole;
+import org.openjdk.jmh.results.format.ResultFormatType;
+import org.openjdk.jmh.runner.Runner;
+import org.openjdk.jmh.runner.options.Options;
+import org.openjdk.jmh.runner.options.OptionsBuilder;
+
+/**
+ * This tests the cost of creating exchanges.
+ */
+public class CoreObjectsCreationTest {
+
+ @Test
+ public void launchBenchmark() throws Exception {
+ Options opt = new OptionsBuilder()
+ // Specify which benchmarks to run.
+ // You can be more specific if you'd like to run only one
benchmark per test.
+ .include(this.getClass().getName() + ".*")
+ // Set the following options as needed
+ .measurementIterations(10)
+ .warmupIterations(5)
+ .forks(1)
+ .resultFormat(ResultFormatType.JSON)
+ .result(this.getClass().getSimpleName() + ".jmh.json")
+ .build();
+
+ new Runner(opt).run();
+ }
+
+ // The JMH samples are the best documentation for how to use it
+ //
http://hg.openjdk.java.net/code-tools/jmh/file/tip/jmh-samples/src/main/java/org/openjdk/jmh/samples/
+ @State(Scope.Benchmark)
+ public static class BenchmarkState {
+ CamelContext context;
+
+ @Setup(Level.Trial)
+ public void initialize() throws Exception {
+ context = new DefaultCamelContext();
+
+ context.start();
+ }
+ }
+
+ @OutputTimeUnit(TimeUnit.MICROSECONDS)
+ @BenchmarkMode(Mode.AverageTime)
+ @Benchmark
+ public void createDefaultExchange(BenchmarkState state, Blackhole bh) {
+ DefaultExchange de = new DefaultExchange(state.context);
+
+ bh.consume(de);
+ }
+
+ @OutputTimeUnit(TimeUnit.MICROSECONDS)
+ @BenchmarkMode(Mode.AverageTime)
+ @Benchmark
+ public void createDefaultMessage(BenchmarkState state, Blackhole bh) {
+ DefaultMessage dm = new DefaultMessage(state.context);
+
+ bh.consume(dm);
+ }
+}