anuragdy commented on PR #666:
URL: https://github.com/apache/tomcat/pull/666#issuecomment-1715600463

   Benchmarks with JMH
   
   #### JDK11
   ```
   Benchmark                      Mode  Cnt         Score        Error  Units
   MyBenchmark.runNewTest        thrpt    5  20981286.747 ±  52439.964  ops/s
   MyBenchmark.runOldTest        thrpt    5   9725982.396 ± 887782.808  ops/s
   MyBenchmark.runSecondNewTest  thrpt    5  45765078.184 ± 787752.738  ops/s
   ```
   #### JDK8
   ```
   Benchmark                      Mode  Cnt         Score         Error  Units
   MyBenchmark.runNewTest        thrpt    5  25402245.677 ± 2107638.349  ops/s
   MyBenchmark.runOldTest        thrpt    5  14939262.248 ±  632445.140  ops/s
   MyBenchmark.runSecondNewTest  thrpt    5  51103154.143 ± 1789043.949  ops/s
   ```
   
   JMH Test Code -
   ```
   package org.sample;
   
   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.State;
   import org.openjdk.jmh.annotations.Warmup;
   
   import java.util.Arrays;
   import java.util.HashMap;
   import java.util.concurrent.TimeUnit;
   
   
   public class MyBenchmark {
   
       @State(org.openjdk.jmh.annotations.Scope.Benchmark)
       public static class BenchmarkState {
           private static final String[] SCOPE_NAMES =
                   new String[]{"applicationScope", "cookie", "header", 
"headerValues", "initParam", "pageContext", "pageScope", "param",
                           "paramValues", "requestScope", "sessionScope"};
           private static final String[] TEST_SCOPES =
                   {"requestScope", "pageScope", "sessionScope", "pageContext", 
"header", "applicationScope", "cookie", "headerValues",
                           "initParam", "param", "paramValues"};
       }
   
       @Benchmark
       @BenchmarkMode(Mode.Throughput)
       @Fork(value = 1, warmups = 1)
       public void runOldTest(BenchmarkState state) {
           for (int i = 0; i < state.TEST_SCOPES.length; i++) {
               Arrays.binarySearch(state.SCOPE_NAMES, state.TEST_SCOPES[i]);
           }
       }
   
       @Benchmark
       @BenchmarkMode(Mode.Throughput)
       @Fork(value = 1, warmups = 1)
       public void runNewTest(BenchmarkState state) {
           int foundScope = -1;
           for (int i = 0; i < state.TEST_SCOPES.length; i++) {
               String scope = state.TEST_SCOPES[i];
               switch (scope) {
                   case "requestScope":
                       foundScope = 1;
                       break;
                   case "pageScope":
                       foundScope = 2;
                       break;
                   case "sessionScope":
                       foundScope = 3;
                       break;
                   case "pageContext":
                       foundScope = 4;
                       break;
                   case "header":
                       foundScope = 5;
                       break;
                   case "applicationScope":
                       foundScope = 6;
                       break;
                   case "cookie":
                       foundScope = 7;
                       break;
                   case "headerValues":
                       foundScope = 8;
                       break;
                   case "initParam":
                       foundScope = 9;
                       break;
                   case "param":
                       foundScope = 10;
                       break;
                   case "paramValues":
                       foundScope = 11;
                       break;
                   default:
                       throw new RuntimeException("Did not find scope for value 
" + scope);
               }
               if (foundScope < 0) {
                   throw new RuntimeException();
               }
           }
       }
   
       @Benchmark
       @BenchmarkMode(Mode.Throughput)
       @Fork(value = 1, warmups = 1)
       public void runSecondNewTest(BenchmarkState state) {
           for (int i = 0; i < state.TEST_SCOPES.length; i++) {
               Scope.fromValue(state.TEST_SCOPES[i]);
           }
       }
   
       public static void main(String[] args) throws Exception {
           org.openjdk.jmh.Main.main(args);
       }
   
       private enum Scope {
           applicationScope(0), cookie(1), header(2), headerValues(3), 
initParam(4), pageContext(5), pageScope(6), param(7), paramValues(8),
           requestScope(9), sessionScope(10);
   
           final public int idx;
           private static final HashMap<String, Scope> lookupMap = new 
HashMap<>();
   
           static {
               for (Scope scope : Scope.values()) {
                   lookupMap.put(scope.name().toLowerCase(), scope);
               }
           }
   
           Scope(int idx) {
               this.idx = idx;
           }
   
           public static Scope fromValue(String value) {
               return lookupMap.get(value);
           }
       }
   }
   ```
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to