Repository: camel
Updated Branches:
  refs/heads/master 7d0c5685e -> 0b2da55ac


Add jmh test


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/9f32c398
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/9f32c398
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/9f32c398

Branch: refs/heads/master
Commit: 9f32c3988b549c868456efd824fdc5670f49e4a7
Parents: 7d0c568
Author: Claus Ibsen <davscl...@apache.org>
Authored: Thu Jun 29 20:38:45 2017 +0200
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Thu Jun 29 20:44:47 2017 +0200

----------------------------------------------------------------------
 .../itest/jmh/SimpleCachedExpressionTest.java   | 112 +++++++++++++++++++
 .../camel/itest/jmh/SimpleExpressionTest.java   | 111 ++++++++++++++++++
 2 files changed, 223 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/9f32c398/tests/camel-jmh/src/test/java/org/apache/camel/itest/jmh/SimpleCachedExpressionTest.java
----------------------------------------------------------------------
diff --git 
a/tests/camel-jmh/src/test/java/org/apache/camel/itest/jmh/SimpleCachedExpressionTest.java
 
b/tests/camel-jmh/src/test/java/org/apache/camel/itest/jmh/SimpleCachedExpressionTest.java
new file mode 100644
index 0000000..0532dde
--- /dev/null
+++ 
b/tests/camel-jmh/src/test/java/org/apache/camel/itest/jmh/SimpleCachedExpressionTest.java
@@ -0,0 +1,112 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.camel.itest.jmh;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.Expression;
+import org.apache.camel.builder.ExpressionBuilder;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.impl.DefaultExchange;
+import org.junit.Test;
+import org.openjdk.jmh.annotations.Benchmark;
+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.infra.Blackhole;
+import org.openjdk.jmh.runner.Runner;
+import org.openjdk.jmh.runner.options.Options;
+import org.openjdk.jmh.runner.options.OptionsBuilder;
+import org.openjdk.jmh.runner.options.TimeValue;
+
+/**
+ * Tests a Simple expression
+ */
+public class SimpleCachedExpressionTest {
+
+    @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
+            .mode(Mode.All)
+            .timeUnit(TimeUnit.MICROSECONDS)
+            .warmupTime(TimeValue.seconds(1))
+            .warmupIterations(2)
+            .measurementTime(TimeValue.seconds(1))
+            .measurementIterations(2)
+            .threads(2)
+            .forks(1)
+            .shouldFailOnError(true)
+            .shouldDoGC(true)
+            .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.Thread)
+    public static class BenchmarkState {
+        CamelContext camel;
+        String expression = "Hello ${body}";
+        Exchange exchange;
+        Expression cached;
+
+        @Setup(Level.Trial)
+        public void initialize() {
+            camel = new DefaultCamelContext();
+            try {
+                camel.start();
+                exchange = new DefaultExchange(camel);
+                exchange.getIn().setBody("World");
+                cached = ExpressionBuilder.simpleExpression(expression);
+            } catch (Exception e) {
+                // ignore
+            }
+        }
+
+        @TearDown(Level.Trial)
+        public void close() {
+            try {
+                camel.stop();
+            } catch (Exception e) {
+                // ignore
+            }
+        }
+
+    }
+
+    @Benchmark
+    @Measurement(batchSize = 1000)
+    public void simpleCachedExpression(BenchmarkState state, Blackhole bh) {
+        String out = state.cached.evaluate(state.exchange, String.class);
+        if (!out.equals("Hello World")) {
+            throw new IllegalArgumentException("Evaluation failed");
+        }
+        bh.consume(out);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/9f32c398/tests/camel-jmh/src/test/java/org/apache/camel/itest/jmh/SimpleExpressionTest.java
----------------------------------------------------------------------
diff --git 
a/tests/camel-jmh/src/test/java/org/apache/camel/itest/jmh/SimpleExpressionTest.java
 
b/tests/camel-jmh/src/test/java/org/apache/camel/itest/jmh/SimpleExpressionTest.java
new file mode 100644
index 0000000..505504f
--- /dev/null
+++ 
b/tests/camel-jmh/src/test/java/org/apache/camel/itest/jmh/SimpleExpressionTest.java
@@ -0,0 +1,111 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.camel.itest.jmh;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.Expression;
+import org.apache.camel.builder.ExpressionBuilder;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.impl.DefaultExchange;
+import org.junit.Test;
+import org.openjdk.jmh.annotations.Benchmark;
+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.infra.Blackhole;
+import org.openjdk.jmh.runner.Runner;
+import org.openjdk.jmh.runner.options.Options;
+import org.openjdk.jmh.runner.options.OptionsBuilder;
+import org.openjdk.jmh.runner.options.TimeValue;
+
+/**
+ * Tests a Simple expression
+ */
+public class SimpleExpressionTest {
+
+    @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
+            .mode(Mode.All)
+            .timeUnit(TimeUnit.MICROSECONDS)
+            .warmupTime(TimeValue.seconds(1))
+            .warmupIterations(2)
+            .measurementTime(TimeValue.seconds(1))
+            .measurementIterations(2)
+            .threads(2)
+            .forks(1)
+            .shouldFailOnError(true)
+            .shouldDoGC(true)
+            .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.Thread)
+    public static class BenchmarkState {
+        CamelContext camel;
+        String expression = "Hello ${body}";
+        Exchange exchange;
+
+        @Setup(Level.Trial)
+        public void initialize() {
+            camel = new DefaultCamelContext();
+            try {
+                camel.start();
+                exchange = new DefaultExchange(camel);
+                exchange.getIn().setBody("World");
+            } catch (Exception e) {
+                // ignore
+            }
+        }
+
+        @TearDown(Level.Trial)
+        public void close() {
+            try {
+                camel.stop();
+            } catch (Exception e) {
+                // ignore
+            }
+        }
+
+    }
+
+    @Benchmark
+    @Measurement(batchSize = 1000)
+    public void simpleExpression(BenchmarkState state, Blackhole bh) {
+        Expression simple = 
ExpressionBuilder.simpleExpression(state.expression);
+        String out = simple.evaluate(state.exchange, String.class);
+        if (!out.equals("Hello World")) {
+            throw new IllegalArgumentException("Evaluation failed");
+        }
+        bh.consume(out);
+    }
+
+}

Reply via email to