Created
May 24, 2013 21:31
-
-
Save bchetty/5646657 to your computer and use it in GitHub Desktop.
Simple Caliper Benchmark test program.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import com.google.caliper.Param; | |
| import com.google.caliper.Runner; | |
| import com.google.caliper.SimpleBenchmark; | |
| import java.util.HashMap; | |
| /** | |
| * Simple Caliper Benchmark test program. | |
| * | |
| * @author Babji Prashanth, Chetty | |
| */ | |
| public class CaliperTest1 extends SimpleBenchmark { | |
| @Param({"5", "10", "15", "20"}) private int length; | |
| private HashMap<Integer, Integer> intMap; | |
| @Override | |
| protected void setUp() throws Exception { | |
| this.intMap = new HashMap<Integer, Integer>(); | |
| for(int i=0;i<10000;i++) { | |
| intMap.put(i, i); | |
| } | |
| } | |
| public void timeTestContains1(int reps) { | |
| for (int i = 0; i < reps; i++) { | |
| if(intMap.containsKey(i)) { | |
| Integer someInt = intMap.get(i); | |
| } | |
| } | |
| } | |
| public void timeTestContains2(int reps) { | |
| for (int i = 0; i < reps; i++) { | |
| Integer someInt = intMap.get(i); | |
| if(someInt != null) {} | |
| } | |
| } | |
| public static void main(String[] args) throws Exception { | |
| Runner.main(CaliperTest1.class, args); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment