Skip to content

Instantly share code, notes, and snippets.

@thomasjungblut
Created October 18, 2012 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomasjungblut/3912305 to your computer and use it in GitHub Desktop.
Save thomasjungblut/3912305 to your computer and use it in GitHub Desktop.
Benchmark of sequential disk datastructures
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Writable;
import org.apache.jdbm.DBMaker;
import com.google.caliper.Param;
import com.google.caliper.Runner;
import com.google.caliper.SimpleBenchmark;
import de.jungblut.datastructure.DiskList;
import de.jungblut.datastructure.PrefetchCache;
public class DiskSerializationBenchmark extends SimpleBenchmark {
@Param({ "100000", "1000000", "10000000" })
private int length;
static volatile int SEQ = 0;
@Param
Type type;
enum Type {
DISKLIST, CACHED_DISKLIST, JDBM_LINKEDLIST
}
DiskList<IntWritable> diskList;
PrefetchCache<IntWritable> cachedDiskList;
List<Writable> jdbmLinkedList;
@Override
protected void setUp() throws Exception {
if (type == Type.DISKLIST) {
diskList = new DiskList<>("/tmp/disklist.bin" + (SEQ++));
} else if (type == Type.CACHED_DISKLIST) {
diskList = new DiskList<IntWritable>("/tmp/disklist.bin" + (SEQ++));
cachedDiskList = new PrefetchCache<>(diskList, IntWritable.class, length / 10 + 1);
} else {
jdbmLinkedList = DBMaker
.openFile("/tmp/database.bin" + (SEQ++))
.closeOnExit()
.disableCache()
.make()
.createLinkedList("LIST!" + (SEQ++),
new WritableSerialization<>(IntWritable.class));
}
}
public void timeRead(int reps) throws Exception {
for (int iteration = 0; iteration < reps; iteration++) {
setUp();
long x = 0;
IntWritable instance = new IntWritable();
if (type == Type.DISKLIST) {
fill(instance);
// now read
while (diskList.poll(instance) != null)
x++;
} else if (type == Type.CACHED_DISKLIST) {
fill(instance);
while (cachedDiskList.poll() != null)
x++;
} else {
for (int i = 0; i < length; i++) {
instance.set(i);
jdbmLinkedList.add(instance);
}
Iterator<Writable> iterator = jdbmLinkedList.iterator();
while (iterator.hasNext()) {
IntWritable next = (IntWritable) iterator.next();
x += next.get();
}
}
System.out.println(x);
}
}
public void fill(IntWritable instance) throws IOException {
for (int i = 0; i < length; i++) {
instance.set(i);
diskList.add(instance);
}
diskList.closeWrite();
diskList.openRead();
}
@Override
protected void tearDown() throws Exception {
if (type == Type.DISKLIST) {
diskList.close();
} else if (type == Type.CACHED_DISKLIST) {
diskList.close();
}
}
public static void main(String[] args) {
Runner.main(DiskSerializationBenchmark.class, args);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment