Skip to content

Instantly share code, notes, and snippets.

@bchetty
Created May 24, 2013 21:31
Show Gist options
  • Select an option

  • Save bchetty/5646657 to your computer and use it in GitHub Desktop.

Select an option

Save bchetty/5646657 to your computer and use it in GitHub Desktop.
Simple Caliper Benchmark test program.
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&lt;Integer, Integer&gt;();
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