Home | History | Annotate | Download | only in benchmarks
      1 /*
      2  * Copyright (C) 2015 Google Inc.
      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;
     18 
     19 import junit.framework.Assert;
     20 
     21 public class ClassLoaderResourceBenchmark {
     22 
     23   private static final String EXISTENT_RESOURCE = "java/util/logging/logging.properties";
     24   private static final String MISSING_RESOURCE = "missing_entry";
     25 
     26   public void timeGetBootResource_hit(int reps) {
     27     ClassLoader currentClassLoader = getClass().getClassLoader();
     28     Assert.assertNotNull(currentClassLoader.getResource(EXISTENT_RESOURCE));
     29 
     30     for (int rep = 0; rep < reps; ++rep) {
     31       currentClassLoader.getResource(EXISTENT_RESOURCE);
     32     }
     33   }
     34 
     35   public void timeGetBootResource_miss(int reps) {
     36     ClassLoader currentClassLoader = getClass().getClassLoader();
     37     Assert.assertNull(currentClassLoader.getResource(MISSING_RESOURCE));
     38 
     39     for (int rep = 0; rep < reps; ++rep) {
     40       currentClassLoader.getResource(MISSING_RESOURCE);
     41     }
     42   }
     43 
     44 }
     45