Mercurial > stress-tester
changeset 606:2e185909d22c
HttpMessagePredicateBenchmark
author | Devel 1 |
---|---|
date | Mon, 09 Oct 2017 09:08:32 +0200 |
parents | 5c0b5bfd2972 |
children | 765556dd7c80 |
files | stress-tester-benchmark/src/main/java/com/passus/st/client/http/filter/HttpMessagePredicateBenchmark.java |
diffstat | 1 files changed, 49 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester-benchmark/src/main/java/com/passus/st/client/http/filter/HttpMessagePredicateBenchmark.java Mon Oct 09 09:07:31 2017 +0200 +++ b/stress-tester-benchmark/src/main/java/com/passus/st/client/http/filter/HttpMessagePredicateBenchmark.java Mon Oct 09 09:08:32 2017 +0200 @@ -1,9 +1,14 @@ package com.passus.st.client.http.filter; import com.passus.filter.config.PredicateNodeTransformer; +import com.passus.net.http.HttpRequest; +import com.passus.net.http.HttpRequestBuilder; +import com.passus.net.http.HttpResponse; +import com.passus.net.http.HttpResponseBuilder; import com.passus.st.AppUtils; import com.passus.utils.AllocationUtils; import java.util.concurrent.TimeUnit; +import java.util.function.Predicate; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; @@ -31,7 +36,25 @@ @Warmup(iterations = 6) public class HttpMessagePredicateBenchmark { - private final PredicateNodeTransformer nodeTransformer = new PredicateNodeTransformer(); + private static final PredicateNodeTransformer TRANSFORMER = new PredicateNodeTransformer(); + + private static HttpMessagePredicate predicate(String config) { + try { + Predicate predicate = TRANSFORMER.transform(config); + return new HttpMessagePredicate(predicate); + } catch (Exception e) { + throw new RuntimeException(e.getMessage(), e); + } + } + + private final HttpMessagePredicate reqUriPred = predicate("{req.uri: '/logout'}"); + private final HttpMessagePredicate reqUrlPred = predicate("{req.url: '/logout'}"); + private final HttpMessagePredicate respStatusCodePred = predicate("{resp.status.code: 200}"); + private final HttpMessagePredicate compound = predicate("{req.uri: '/logout', req.url: '/logout', resp.status.code: 200}"); + + private final HttpRequest req = HttpRequestBuilder.get("http://test.com/logout").build(); + private final HttpResponse resp = HttpResponseBuilder.ok().build(); + private final HttpMessageWrapper wrapper = new HttpMessageWrapper(req, resp, null); @Setup public static void beforeClass() { @@ -44,15 +67,34 @@ } @Benchmark - public Object test1() { - return this; + public Object reqUriPred() { + return reqUriPred.test(wrapper); } - public static void main(String[] args) throws Throwable { - Options opt = new OptionsBuilder().include(CsrfBenchmark.class.getSimpleName() + ".*").build(); + @Benchmark + public Object reqUrlPred() { + return reqUrlPred.test(wrapper); + } + + @Benchmark + public Object compound() { + return compound.test(wrapper); + } + + @Benchmark + public Object respStatusCodePred() { + return respStatusCodePred.test(wrapper); + } + + 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(); AllocationUtils au = new AllocationUtils(); - + au.setCount(30_000); + au.checkAllocation("compound", bench::compound); + au.checkAllocation("reqUri", bench::reqUriPred); + au.checkAllocation("reqUrl", bench::reqUrlPred); + au.checkAllocation("respStatusCode", bench::respStatusCodePred); } }