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
17package org.conscrypt;
18
19import com.google.caliper.BeforeExperiment;
20import com.google.caliper.Benchmark;
21import com.google.caliper.Param;
22import org.conscrypt.EngineHandshakeBenchmark.Config;
23
24/**
25 * Cipher benchmarks. Only runs on AES currently because of the combinatorial
26 * explosion of the test as it stands.
27 */
28@SuppressWarnings("unused")
29public class CaliperAlpnBenchmark {
30    private final CaliperConfig config = new CaliperConfig();
31
32    @Param({TestUtils.TEST_CIPHER})
33    public String a_cipher;
34
35    @Param
36    public BufferType b_buffer;
37
38    @Param
39    public AndroidEngineFactory c_engine;
40
41    private EngineHandshakeBenchmark benchmark;
42
43    @BeforeExperiment
44    public void setUp() throws Exception {
45        benchmark = new EngineHandshakeBenchmark(config);
46    }
47
48    @Benchmark
49    public void timeHandshake(int reps) throws Exception {
50        for (int i = 0; i < reps; ++i) {
51            benchmark.handshake();
52        }
53    }
54
55    private final class CaliperConfig implements Config {
56        @Override
57        public BufferType bufferType() {
58            return b_buffer;
59        }
60
61        @Override
62        public EngineFactory engineFactory() {
63            return c_engine;
64        }
65
66        @Override
67        public String cipher() {
68            return a_cipher;
69        }
70
71        @Override
72        public boolean useAlpn() {
73            return true;
74        }
75    }
76}
77