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 javax.net.ssl.SSLException; 36 import org.conscrypt.EngineWrapBenchmark.Config; 37 import org.openjdk.jmh.annotations.Benchmark; 38 import org.openjdk.jmh.annotations.Fork; 39 import org.openjdk.jmh.annotations.Level; 40 import org.openjdk.jmh.annotations.Param; 41 import org.openjdk.jmh.annotations.Scope; 42 import org.openjdk.jmh.annotations.Setup; 43 import org.openjdk.jmh.annotations.State; 44 import org.openjdk.jmh.annotations.TearDown; 45 import org.openjdk.jmh.annotations.Threads; 46 47 /** 48 * Benchmark comparing performance of various engine implementations to conscrypt. 49 */ 50 @State(Scope.Benchmark) 51 @Fork(1) 52 @Threads(1) 53 public class JmhEngineWrapBenchmark { 54 private final JmhConfig config = new JmhConfig(); 55 56 @Param({TestUtils.TEST_CIPHER}) 57 public String a_cipher; 58 59 @Param 60 public BufferType b_buffer; 61 62 @Param({"128", "4096"}) 63 public int c_message; 64 65 @Param 66 public OpenJdkEngineFactory d_engine; 67 68 private EngineWrapBenchmark benchmark; 69 70 @Setup(Level.Iteration) setup()71 public void setup() throws Exception { 72 benchmark = new EngineWrapBenchmark(config); 73 } 74 75 @TearDown(Level.Iteration) teardown()76 public void teardown() { 77 benchmark.teardown(); 78 } 79 80 @Benchmark wrap()81 public void wrap() throws SSLException { 82 benchmark.wrap(); 83 } 84 85 @Benchmark wrapAndUnwrap()86 public void wrapAndUnwrap() throws SSLException { 87 benchmark.wrapAndUnwrap(); 88 } 89 90 private final class JmhConfig implements Config { 91 92 @Override bufferType()93 public BufferType bufferType() { 94 return b_buffer; 95 } 96 97 @Override engineFactory()98 public EngineFactory engineFactory() { 99 return d_engine; 100 } 101 102 @Override messageSize()103 public int messageSize() { 104 return c_message; 105 } 106 107 @Override cipher()108 public String cipher() { 109 return a_cipher; 110 } 111 } 112 } 113