Guest User

Untitled

a guest
Dec 17th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. package com.geomotiv.ads.benchmarks;
  2.  
  3. import java.util.ArrayDeque;
  4. import java.util.LinkedList;
  5. import org.openjdk.jmh.annotations.Benchmark;
  6. import org.openjdk.jmh.annotations.Scope;
  7. import org.openjdk.jmh.annotations.State;
  8. import org.openjdk.jmh.runner.Runner;
  9. import org.openjdk.jmh.runner.RunnerException;
  10. import org.openjdk.jmh.runner.options.Options;
  11. import org.openjdk.jmh.runner.options.OptionsBuilder;
  12.  
  13. @State(Scope.Benchmark)
  14. public class DequeueBenchmark {
  15. private static final long LIFETIME = 10;
  16.  
  17. private final ArrayDeque<Long> arrayDeque;
  18.  
  19. private final LinkedList<Long> linkedDeque;
  20.  
  21. public DequeueBenchmark() {
  22. this.arrayDeque = new ArrayDeque<>();
  23. this.linkedDeque = new LinkedList<>();
  24. }
  25.  
  26. @Benchmark
  27. public void arrayDequeBenchmark() {
  28. long now = System.currentTimeMillis();
  29. long expire = now - LIFETIME;
  30.  
  31. arrayDeque.addLast(now);
  32.  
  33. while (arrayDeque.getFirst() < expire) {
  34. arrayDeque.removeFirst();
  35. }
  36. }
  37.  
  38. @Benchmark
  39. public void linkedDequeBenchmark() {
  40. long now = System.currentTimeMillis();
  41. long expire = now - LIFETIME;
  42.  
  43. linkedDeque.addLast(now);
  44.  
  45. while (linkedDeque.getFirst() < expire) {
  46. linkedDeque.removeFirst();
  47. }
  48. }
  49.  
  50. public static void main(String[] args) throws RunnerException {
  51. Options opt = new OptionsBuilder()
  52. .include(DequeueBenchmark.class.getSimpleName())
  53. .warmupIterations(3)
  54. .measurementIterations(3)
  55. .measurementBatchSize(1_000_000)
  56. .threads(1)
  57. .forks(1)
  58. .build();
  59. new Runner(opt).run();
  60. }
  61. }
Add Comment
Please, Sign In to add comment