Created
October 17, 2012 19:49
-
-
Save thomasjungblut/3907709 to your computer and use it in GitHub Desktop.
HAMA-559, caliper benchmark
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
package de.jungblut.benchmark; | |
import java.util.Random; | |
import org.apache.hadoop.conf.Configuration; | |
import org.apache.hadoop.io.IntWritable; | |
import org.apache.hama.bsp.TaskAttemptID; | |
import org.apache.hama.bsp.TaskID; | |
import org.apache.hama.bsp.message.DiskQueue; | |
import org.apache.hama.bsp.message.MessageQueue; | |
import org.apache.hama.bsp.message.SpillingQueue; | |
import com.google.caliper.Param; | |
import com.google.caliper.Runner; | |
import com.google.caliper.SimpleBenchmark; | |
public class SpillBenchmark extends SimpleBenchmark { | |
@Param({ "10", "100", "1000", "10000", "100000", "1000000" }) | |
private int size; | |
@Param | |
Type type; | |
public enum Type { | |
SPILLING_QUEUE, DISK_QUEUE | |
}; | |
int[] array; | |
MessageQueue<IntWritable> queue; | |
@Override | |
protected void setUp() throws Exception { | |
array = new int[size]; | |
Random r = new Random(); | |
for (int i = 0; i < size; i++) { | |
array[i] = r.nextInt(); | |
} | |
if (type == Type.DISK_QUEUE) { | |
queue = new DiskQueue<>(); | |
} else { | |
queue = new SpillingQueue<>(); | |
} | |
Configuration configuration = new Configuration(); | |
queue.init(configuration, | |
new TaskAttemptID(new TaskID("bla", 1, 1337), r.nextInt(100000))); | |
} | |
public void timeSpill(int reps) { | |
for (int rep = 0; rep < reps; rep++) { | |
int sum = 0; | |
for (int i = 0; i < size; i++) { | |
queue.add(new IntWritable(array[i])); | |
sum += i; | |
} | |
System.out.println(sum); | |
} | |
} | |
public static void main(String[] args) { | |
Runner.main(SpillBenchmark.class, args); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment