changeset 614:50ef5ab06550

benchmarks
author Devel 1
date Tue, 10 Oct 2017 10:55:13 +0200
parents e38011acae15
children 6019422b29de
files stress-tester-benchmark/src/main/java/com/passus/st/client/http/filter/HttpMessageHelperBenchmark.java stress-tester-benchmark/src/main/java/com/passus/st/client/http/filter/HttpMessagePredicateBenchmark.java
diffstat 2 files changed, 83 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/stress-tester-benchmark/src/main/java/com/passus/st/client/http/filter/HttpMessageHelperBenchmark.java	Tue Oct 10 10:55:13 2017 +0200
@@ -0,0 +1,80 @@
+package com.passus.st.client.http.filter;
+
+import com.passus.data.ByteString;
+import com.passus.net.http.HttpMessageHelper;
+import com.passus.net.http.HttpRequest;
+import com.passus.net.http.HttpRequestBuilder;
+import com.passus.st.AppUtils;
+import com.passus.utils.AllocationUtils;
+import java.util.concurrent.TimeUnit;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Fork;
+import org.openjdk.jmh.annotations.Measurement;
+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.annotations.TearDown;
+import org.openjdk.jmh.annotations.Warmup;
+import org.openjdk.jmh.runner.Runner;
+import org.openjdk.jmh.runner.options.Options;
+import org.openjdk.jmh.runner.options.OptionsBuilder;
+
+/**
+ *
+ * @author mikolaj.podbielski
+ */
+@State(Scope.Thread)
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.MICROSECONDS)
+@Fork(value = 1)
+@Measurement(iterations = 6)
+@Warmup(iterations = 6)
+public class HttpMessageHelperBenchmark {
+
+    private static final String COOKIE_NAME = "jsessid";
+    private static final String COOKIE_VALUE = "0123456789abcdf";
+    private static final ByteString COOKIE_NAME_BS = ByteString.create(COOKIE_NAME);
+    private static final ByteString COOKIE_VALUE_BS = ByteString.create(COOKIE_VALUE);
+
+    private final HttpMessageHelper helper = new HttpMessageHelper(false);
+
+    private final HttpRequest request = HttpRequestBuilder.get("http://www.example.net")
+            .header("abc", "def").cookie(COOKIE_NAME, COOKIE_VALUE).build();
+
+    @Setup
+    public static void beforeClass() {
+        AppUtils.registerAll();
+    }
+
+    @TearDown
+    public static void afterClass() {
+        AppUtils.unregisterAll();
+    }
+
+    @Benchmark
+    public Object setCookie() {
+        helper.setCookie(request, COOKIE_NAME_BS, COOKIE_VALUE_BS);
+        return request;
+    }
+
+    @Benchmark
+    public Object setCookieFromString() {
+        helper.setCookie(request, COOKIE_NAME, COOKIE_VALUE);
+        return request;
+    }
+
+    public static void main(String[] args) throws Exception {
+        Options opt = new OptionsBuilder().include(HttpMessageHelperBenchmark.class.getSimpleName() + ".*").build();
+        new Runner(opt).run();
+
+        HttpMessageHelperBenchmark bench = new HttpMessageHelperBenchmark();
+        beforeClass();
+
+        AllocationUtils au = new AllocationUtils();
+        au.checkAllocation("setCookie  S", bench::setCookieFromString);
+        au.checkAllocation("setCookie BS", bench::setCookie);
+    }
+}
--- a/stress-tester-benchmark/src/main/java/com/passus/st/client/http/filter/HttpMessagePredicateBenchmark.java	Mon Oct 09 15:28:51 2017 +0200
+++ b/stress-tester-benchmark/src/main/java/com/passus/st/client/http/filter/HttpMessagePredicateBenchmark.java	Tue Oct 10 10:55:13 2017 +0200
@@ -89,7 +89,10 @@
     public static void main(String[] args) throws Exception {
         Options opt = new OptionsBuilder().include(HttpMessagePredicateBenchmark.class.getSimpleName() + ".*").build();
         new Runner(opt).run();
+
         HttpMessagePredicateBenchmark bench = new HttpMessagePredicateBenchmark();
+        beforeClass();
+
         AllocationUtils au = new AllocationUtils();
         au.setCount(30_000);
         au.checkAllocation("compound", bench::compound);