import java.util.Random; import com.google.caliper.Runner; import com.google.caliper.SimpleBenchmark; public class SideOfZero { public static class Benchmark1 extends SimpleBenchmark { private Random r; private int[] nums = new int[2000]; public void setUp() { r = new Random(); for(int i = 0; i < 2000; i++) { nums[i] = r.nextInt(); } } public int timeXOR(int reps) { int total = 0; for(int i = 0; i < reps; i++) { for(int j = 0; j < 1000; j++) { if(nums[2*j] == 0 || nums[2*j+1] == 0) { // nothing } else if((nums[2*j] ^ nums[2*j+1]) < 0) { total++; } else { total--; } } } return total; } public int timeIfs(int reps) { int total = 0; for(int i = 0; i < reps; i++) { for(int j = 0; j < 1000; j++) { if(nums[2*j] == 0 || nums[2*j+1] == 0) { // nothing } else if((nums[2*j] > 0 && nums[2*j+1] > 0) || (nums[2*j] < 0 && nums[2*j+1] < 0)) { total++; } else { total--; } } } return total; } } public static void main(String... args) { Runner.main(Benchmark1.class, args); } }