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 public class ProviderBenchmark { 24 public void timeStableProviders(int reps) throws Exception { 25 for (int i = 0; i < reps; ++i) { 26 Cipher c = Cipher.getInstance("RSA"); 27 } 28 } 29 30 public void timeWithNewProvider(int reps) throws Exception { 31 for (int i = 0; i < reps; ++i) { 32 Security.addProvider(new MockProvider()); 33 try { 34 Cipher c = Cipher.getInstance("RSA"); 35 } finally { 36 Security.removeProvider("Mock"); 37 } 38 } 39 } 40 41 private static class MockProvider extends Provider { 42 public MockProvider() { 43 super("Mock", 1.0, "Mock me!"); 44 } 45 } 46 } 47