• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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 benchmarks.regression;
18 
19 import java.security.Provider;
20 import java.security.Security;
21 import javax.crypto.Cipher;
22 
23 import com.google.caliper.Param;
24 import com.google.caliper.SimpleBenchmark;
25 import javax.net.ssl.SSLSocketFactory;
26 
27 public class ProviderBenchmark extends SimpleBenchmark {
timeStableProviders(int reps)28     public void timeStableProviders(int reps) throws Exception {
29         for (int i = 0; i < reps; ++i) {
30             Cipher c = Cipher.getInstance("RSA");
31         }
32     }
33 
timeWithNewProvider(int reps)34     public void timeWithNewProvider(int reps) throws Exception {
35         for (int i = 0; i < reps; ++i) {
36             Security.addProvider(new MockProvider());
37             try {
38                 Cipher c = Cipher.getInstance("RSA");
39             } finally {
40                 Security.removeProvider("Mock");
41             }
42         }
43     }
44 
45     private static class MockProvider extends Provider {
MockProvider()46         public MockProvider() {
47             super("Mock", 1.0, "Mock me!");
48         }
49     }
50 }
51