Search in sources :

Example 6 with Benchmark

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;
}
Also used : CRC32(java.util.zip.CRC32) Benchmark(com.google.caliper.Benchmark)

Example 7 with Benchmark

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;
}
Also used : Adler32(java.util.zip.Adler32) Benchmark(com.google.caliper.Benchmark)

Example 8 with Benchmark

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;
}
Also used : Element(com.google.common.collect.CollectionBenchmarkSampleData.Element) Benchmark(com.google.caliper.Benchmark)

Example 9 with Benchmark

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;
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) Footprint(com.google.caliper.api.Footprint) Benchmark(com.google.caliper.Benchmark)

Example 10 with Benchmark

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;
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) Footprint(com.google.caliper.api.Footprint) Benchmark(com.google.caliper.Benchmark)

Aggregations

Benchmark (com.google.caliper.Benchmark)15 Footprint (com.google.caliper.api.Footprint)8 CountDownLatch (java.util.concurrent.CountDownLatch)4 Element (com.google.common.collect.CollectionBenchmarkSampleData.Element)2 MoreExecutors.directExecutor (com.google.common.util.concurrent.MoreExecutors.directExecutor)2 Executor (java.util.concurrent.Executor)2 GetCheckedTypeValidator (com.google.common.util.concurrent.FuturesGetChecked.GetCheckedTypeValidator)1 FuturesGetChecked.isCheckedException (com.google.common.util.concurrent.FuturesGetChecked.isCheckedException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 URISyntaxException (java.net.URISyntaxException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 NotOwnerException (java.security.acl.NotOwnerException)1 TooManyListenersException (java.util.TooManyListenersException)1 BrokenBarrierException (java.util.concurrent.BrokenBarrierException)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1