Search in sources :

Example 11 with Benchmark

use of com.google.caliper.Benchmark in project guava by google.

the class ExecutionListBenchmark method addThenExecute_multiThreaded.

@Benchmark
int addThenExecute_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);
        for (int j = 0; j < NUM_THREADS; j++) {
            executorService.submit(addTask);
        }
        executorService.submit(executeTask);
        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)

Example 12 with Benchmark

use of com.google.caliper.Benchmark in project guava by google.

the class MoreExecutorsDirectExecutorBenchmark method timeUncontendedExecute.

@Benchmark
int timeUncontendedExecute(int reps) {
    final Executor executor = this.executor;
    final CountingRunnable countingRunnable = this.countingRunnable;
    for (int i = 0; i < reps; i++) {
        executor.execute(countingRunnable);
    }
    return countingRunnable.integer.get();
}
Also used : Executor(java.util.concurrent.Executor) MoreExecutors.directExecutor(com.google.common.util.concurrent.MoreExecutors.directExecutor) Footprint(com.google.caliper.api.Footprint) Benchmark(com.google.caliper.Benchmark)

Example 13 with Benchmark

use of com.google.caliper.Benchmark in project guava by google.

the class MapBenchmark method iterateValuesAndGet.

@Benchmark
boolean iterateValuesAndGet(int reps) {
    Map<Element, Element> map = mapToTest;
    boolean dummy = false;
    for (int i = 0; i < reps; i++) {
        for (Element key : map.values()) {
            // This normally wouldn't make sense, but because our keys are our values it kind of does
            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 14 with Benchmark

use of com.google.caliper.Benchmark in project guava by google.

the class BaseEncodingBenchmark method decodingStream.

@Benchmark
public int decodingStream(int reps) throws IOException {
    int tmp = 0;
    byte[] target = new byte[n];
    for (int i = 0; i < reps; i++) {
        StringReader source = new StringReader(decodingInputs[i & INPUTS_MASK]);
        InputStream decodingStream = encoding.encoding.decodingStream(source);
        decodingStream.read(target);
        decodingStream.close();
        tmp += target[0];
    }
    return tmp;
}
Also used : InputStream(java.io.InputStream) StringReader(java.io.StringReader) Benchmark(com.google.caliper.Benchmark)

Example 15 with Benchmark

use of com.google.caliper.Benchmark in project guava by google.

the class BaseEncodingBenchmark method encodingStream.

@Benchmark
public int encodingStream(int reps) throws IOException {
    int tmp = 0;
    for (int i = 0; i < reps; i++) {
        StringWriter target = new StringWriter(2 * n);
        OutputStream encodingStream = encoding.encoding.encodingStream(target);
        encodingStream.write(encodingInputs[i & INPUTS_MASK]);
        encodingStream.close();
        tmp += target.getBuffer().length();
    }
    return tmp;
}
Also used : StringWriter(java.io.StringWriter) OutputStream(java.io.OutputStream) 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