Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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();
- }
- }
Add Comment
Please, Sign In to add comment