use of com.google.caliper.Benchmark in project guava by google.
the class ChecksumBenchmark method crc32Checksum.
@Benchmark
byte crc32Checksum(int reps) throws Exception {
byte result = 0x01;
for (int i = 0; i < reps; i++) {
CRC32 checksum = new CRC32();
checksum.update(testBytes);
result = (byte) (result ^ checksum.getValue());
}
return result;
}
use of com.google.caliper.Benchmark in project guava by google.
the class ChecksumBenchmark method adler32Checksum.
@Benchmark
byte adler32Checksum(int reps) throws Exception {
byte result = 0x01;
for (int i = 0; i < reps; i++) {
Adler32 checksum = new Adler32();
checksum.update(testBytes);
result = (byte) (result ^ checksum.getValue());
}
return result;
}
use of com.google.caliper.Benchmark in project guava by google.
the class MapBenchmark method iterateWithKeySetAndGet.
@Benchmark
boolean iterateWithKeySetAndGet(int reps) {
Map<Element, Element> map = mapToTest;
boolean dummy = false;
for (int i = 0; i < reps; i++) {
for (Element key : map.keySet()) {
Element value = map.get(key);
dummy ^= key != value;
}
}
return dummy;
}
use of com.google.caliper.Benchmark in project guava by google.
the class ExecutionListBenchmark method addThenExecute_singleThreaded.
@Benchmark
int addThenExecute_singleThreaded(int reps) {
int returnValue = 0;
for (int i = 0; i < reps; i++) {
list = impl.newExecutionList();
listenerLatch = new CountDownLatch(numListeners);
for (int j = 0; j < numListeners; j++) {
list.add(listener, directExecutor());
returnValue += listenerLatch.getCount();
}
list.execute();
returnValue += listenerLatch.getCount();
}
return returnValue;
}
use of com.google.caliper.Benchmark in project guava by google.
the class ExecutionListBenchmark method executeThenAdd_multiThreaded.
@Benchmark
int executeThenAdd_multiThreaded(final int reps) throws InterruptedException {
Runnable addTask = new Runnable() {
@Override
public void run() {
for (int i = 0; i < numListeners; i++) {
list.add(listener, directExecutor());
}
}
};
int returnValue = 0;
for (int i = 0; i < reps; i++) {
list = impl.newExecutionList();
listenerLatch = new CountDownLatch(numListeners * NUM_THREADS);
executorService.submit(executeTask);
for (int j = 0; j < NUM_THREADS; j++) {
executorService.submit(addTask);
}
returnValue += (int) listenerLatch.getCount();
listenerLatch.await();
}
return returnValue;
}
Aggregations