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 /* 18 * Copyright 2017 The Netty Project 19 * 20 * The Netty Project licenses this file to you under the Apache License, 21 * version 2.0 (the "License"); you may not use this file except in compliance 22 * with the License. You may obtain a copy of the License at: 23 * 24 * http://www.apache.org/licenses/LICENSE-2.0 25 * 26 * Unless required by applicable law or agreed to in writing, software 27 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 28 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 29 * License for the specific language governing permissions and limitations 30 * under the License. 31 */ 32 33 package org.conscrypt; 34 35 import com.google.caliper.BeforeExperiment; 36 import com.google.caliper.Benchmark; 37 import com.google.caliper.Param; 38 import org.conscrypt.EngineHandshakeBenchmark.Config; 39 40 /** 41 * Benchmark comparing handshake performance of various engine implementations. 42 */ 43 @SuppressWarnings("unused") 44 public class CaliperEngineHandshakeBenchmark { 45 private final CaliperConfig config = new CaliperConfig(); 46 47 @Param({TestUtils.TEST_CIPHER}) 48 public String a_cipher; 49 50 @Param 51 public BufferType b_buffer; 52 53 @Param({"CONSCRYPT_UNPOOLED"}) 54 public AndroidEngineFactory c_engine; 55 56 @Param 57 public BenchmarkProtocol d_protocol; 58 59 @Param({"100"}) 60 public int e_rtt; 61 62 private EngineHandshakeBenchmark benchmark; 63 64 @BeforeExperiment setUp()65 public void setUp() throws Exception { 66 benchmark = new EngineHandshakeBenchmark(config); 67 } 68 69 @Benchmark timeHandshake(int reps)70 public void timeHandshake(int reps) throws Exception { 71 for (int i = 0; i < reps; ++i) { 72 benchmark.handshake(); 73 } 74 } 75 76 private final class CaliperConfig implements Config { 77 @Override bufferType()78 public BufferType bufferType() { 79 return b_buffer; 80 } 81 82 @Override engineFactory()83 public EngineFactory engineFactory() { 84 return c_engine; 85 } 86 87 @Override cipher()88 public String cipher() { 89 return a_cipher; 90 } 91 92 @Override useAlpn()93 public boolean useAlpn() { 94 return false; 95 } 96 97 @Override protocol()98 public BenchmarkProtocol protocol() { 99 return d_protocol; 100 } 101 102 @Override rttMillis()103 public int rttMillis() { 104 return e_rtt; 105 } 106 } 107 } 108