Created
December 14, 2017 18:10
-
-
Save vchimishuk/77fcb1e2b22a3d92a2a413a2878f767d to your computer and use it in GitHub Desktop.
Revisions
-
vchimishuk created this gist
Dec 14, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,61 @@ package com.geomotiv.ads.benchmarks; import java.util.ArrayDeque; import java.util.LinkedList; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.Scope; import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; @State(Scope.Benchmark) public class DequeueBenchmark { private static final long LIFETIME = 10; private final ArrayDeque<Long> arrayDeque; private final LinkedList<Long> linkedDeque; public DequeueBenchmark() { this.arrayDeque = new ArrayDeque<>(); this.linkedDeque = new LinkedList<>(); } @Benchmark public void arrayDequeBenchmark() { long now = System.currentTimeMillis(); long expire = now - LIFETIME; arrayDeque.addLast(now); while (arrayDeque.getFirst() < expire) { arrayDeque.removeFirst(); } } @Benchmark public void linkedDequeBenchmark() { long now = System.currentTimeMillis(); long expire = now - LIFETIME; linkedDeque.addLast(now); while (linkedDeque.getFirst() < expire) { linkedDeque.removeFirst(); } } public static void main(String[] args) throws RunnerException { Options opt = new OptionsBuilder() .include(DequeueBenchmark.class.getSimpleName()) .warmupIterations(3) .measurementIterations(3) .measurementBatchSize(1_000_000) .threads(1) .forks(1) .build(); new Runner(opt).run(); } }