### Question:
SegmentList { public void clear() { while (!this.segments.isEmpty()) { RecycleUtil.recycle(this.segments.pollLast()); } this.size = this.firstOffset = 0; } SegmentList(final boolean recycleSegment); T get(int index); T peekLast(); T peekFirst(); @SuppressWarnings("unchecked") void add(final T e); int size(); int segmentSize(); boolean isEmpty(); void removeFromFirstWhen(final Predicate<T> predicate); void clear(); void removeFromLastWhen(final Predicate<T> predicate); void removeFromFirst(final int toIndex); @SuppressWarnings("unchecked") void addAll(final Collection<T> coll); @Override String toString(); static final int SEGMENT_SIZE; }### Answer:
@Test public void simpleBenchmark() { int warmupRepeats = 10_0000; int repeats = 100_0000; double arrayDequeOps = 0; double segListOps = 0; { ArrayDeque<Integer> deque = new ArrayDeque<>(); System.gc(); benchArrayDequeue(warmupRepeats, deque); deque.clear(); System.gc(); long startNs = System.nanoTime(); benchArrayDequeue(repeats, deque); long costMs = (System.nanoTime() - startNs) / repeats; arrayDequeOps = repeats * 3.0 / costMs * 1000; System.out.println("ArrayDeque, cost:" + costMs + ", ops: " + arrayDequeOps); } { System.gc(); benchSegmentList(warmupRepeats); this.list.clear(); System.gc(); long startNs = System.nanoTime(); benchSegmentList(repeats); long costMs = (System.nanoTime() - startNs) / repeats; segListOps = repeats * 3.0 / costMs * 1000; System.out.println("SegmentList, cost:" + costMs + ", ops: " + segListOps); this.list.clear(); } System.out.println("Improvement:" + Math.round((segListOps - arrayDequeOps) / arrayDequeOps * 100) + "%"); }