1 /* 2 * Copyright 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package org.conscrypt; 18 19 import javax.net.ssl.SSLException; 20 import org.conscrypt.EngineHandshakeBenchmark.Config; 21 import org.openjdk.jmh.annotations.Benchmark; 22 import org.openjdk.jmh.annotations.Fork; 23 import org.openjdk.jmh.annotations.Level; 24 import org.openjdk.jmh.annotations.Param; 25 import org.openjdk.jmh.annotations.Scope; 26 import org.openjdk.jmh.annotations.Setup; 27 import org.openjdk.jmh.annotations.State; 28 import org.openjdk.jmh.annotations.Threads; 29 30 /** 31 * Benchmark comparing ALPN performance between Conscrypt and Netty. 32 */ 33 @State(Scope.Benchmark) 34 @Fork(1) 35 @Threads(1) 36 public class JmhAlpnBenchmark { 37 private final JmhConfig config = new JmhConfig(); 38 39 @Param({TestUtils.TEST_CIPHER}) 40 public String a_cipher; 41 42 @Param 43 public BufferType b_buffer; 44 45 // JDK does not support ALPN, so exclude it from the benchmarks. 46 @Param({"CONSCRYPT_UNPOOLED", "CONSCRYPT_POOLED", "NETTY", "NETTY_REF_CNT"}) 47 public OpenJdkEngineFactory c_engine; 48 49 private EngineHandshakeBenchmark benchmark; 50 51 @Setup(Level.Iteration) 52 public void setup() throws Exception { 53 benchmark = new EngineHandshakeBenchmark(config); 54 } 55 56 @Benchmark 57 public void hs() throws SSLException { 58 benchmark.handshake(); 59 } 60 61 private final class JmhConfig implements Config { 62 63 @Override 64 public BufferType bufferType() { 65 return b_buffer; 66 } 67 68 @Override 69 public EngineFactory engineFactory() { 70 return c_engine; 71 } 72 73 @Override 74 public String cipher() { 75 return a_cipher; 76 } 77 78 @Override 79 public boolean useAlpn() { 80 return true; 81 } 82 } 83 } 84 85