Home | History | Annotate | Download | only in conscrypt
      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.AfterExperiment;
     36 import com.google.caliper.BeforeExperiment;
     37 import com.google.caliper.Benchmark;
     38 import com.google.caliper.Param;
     39 import javax.net.ssl.SSLException;
     40 import org.conscrypt.EngineWrapBenchmark.Config;
     41 
     42 /**
     43  * Benchmark comparing performance of various engine implementations to conscrypt.
     44  */
     45 @SuppressWarnings("unused")
     46 public class CaliperEngineWrapBenchmark {
     47     private final CaliperConfig config = new CaliperConfig();
     48 
     49     @Param({TestUtils.TEST_CIPHER})
     50     public String a_cipher;
     51 
     52     @Param
     53     public BufferType b_buffer;
     54 
     55     @Param({"64", "512", "4096"})
     56     public int c_message;
     57 
     58     @Param
     59     public AndroidEngineFactory d_engine;
     60 
     61     private EngineWrapBenchmark benchmark;
     62 
     63     @BeforeExperiment
     64     public void setUp() throws Exception {
     65         benchmark = new EngineWrapBenchmark(config);
     66     }
     67 
     68     @AfterExperiment
     69     public void teardown() {
     70         benchmark.teardown();
     71     }
     72 
     73     @Benchmark
     74     public void timeWrap(int reps) throws SSLException {
     75         for (int i = 0; i < reps; ++i) {
     76             benchmark.wrap();
     77         }
     78     }
     79 
     80     public void timeWrapAndUnwrap(int reps) throws SSLException {
     81         for (int i = 0; i < reps; ++i) {
     82             benchmark.wrapAndUnwrap();
     83         }
     84     }
     85 
     86     private final class CaliperConfig implements Config {
     87 
     88         @Override
     89         public BufferType bufferType() {
     90             return b_buffer;
     91         }
     92 
     93         @Override
     94         public EngineFactory engineFactory() {
     95             return d_engine;
     96         }
     97 
     98         @Override
     99         public int messageSize() {
    100             return c_message;
    101         }
    102 
    103         @Override
    104         public String cipher() {
    105             return a_cipher;
    106         }
    107     }
    108 }
    109