Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Linked List Queue vs Double Array Queue vs Queue with Map v3
(version: 0)
Testing a linked list queue vs a double list queue vs Queue with Map for different performance scenarios.
Comparing performance of:
Double Array enque vs Linked List enque vs Queue enqeue vs Array deque vs LinkedList deque vs Queue deque
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
class LinkedListQueue { constructor() { this.length = 0; this.head = undefined; this.tail = undefined; } enqueue(value) { this.enqueueNode(value); } dequeue() { return this.dequeueNode(); } size() { return this.length; } getHead() { return this.head; } getTail() { return this.tail; } enqueueNode(value) { const node = { value, next: undefined }; if (!this.head) { this.head = node; this.tail = node; } else { this.tail.next = node; this.tail = node; } this.length += 1; } dequeueNode() { if (this.head) { const value = this.head.value; this.head = this.head.next; this.length -= 1; return value; } this.tail = undefined; return undefined; } } class DoubleArrayQueue { constructor() { this.input = []; this.output = []; } enqueue(element) { this.input.push(element); } dequeue() { if (this.output.length === 0) { this.pivot(); } return this.output.pop(); } pivot() { this.output = this.input.reverse(); this.input = []; } isEmpty() { return this.input.length === 0 && this.output.length === 0; } } class Queue { #queue = new Map() #head = 0 #tail = 0 enqueue(item) { this.#queue.set(this.#tail, item) this.#tail++ } dequeue() { if (this.#head === this.#tail) return; const value = this.#queue.get(this.#head) this.#queue.delete(this.#tail) this.#head++ return value } size() { return this.#tail - this.#head } } var doubleQ = new DoubleArrayQueue() var linkedListQ = new LinkedListQueue() var queue = new Queue() var queueSize = 100000
Tests:
Double Array enque
for(let i = 0; i < queueSize; i++) { doubleQ.enqueue(i) }
Linked List enque
for(let i = 0; i < queueSize; i++) { linkedListQ.enqueue(i) }
Queue enqeue
for(let i = 0; i < queueSize; i++) { queue.enqueue(i) }
Array deque
for(let i = 0; i < queueSize; i++) { linkedListQ.dequeue() }
LinkedList deque
for(let i = 0; i < queueSize; i++) { linkedListQ.dequeue() }
Queue deque
for(let i = 0; i < queueSize; i++) { queue.dequeue() }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (6)
Previous results
Fork
Test case name
Result
Double Array enque
Linked List enque
Queue enqeue
Array deque
LinkedList deque
Queue deque
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Benchmark Overview** The provided JSON represents a JavaScript benchmark test, specifically measuring the performance of three queue data structures: Double-Ended Queue (Deque), Array, and Queue. **Queue Data Structures** 1. **Double-Ended Queue (Deque)**: A deque is a collection of elements that supports efficient insertion and removal at both ends. 2. **Array**: An array is a built-in JavaScript data structure that allows indexing and slicing for efficient element access. 3. **Queue**: A queue is a First-In-First-Out (FIFO) data structure where elements are added to the end and removed from the front. **Benchmark Test** The benchmark test consists of six test cases: 1. Dequeue operations on each data structure 2. Enqueue operations on each data structure Each test case measures the number of executions per second (ExecutionsPerSecond) for each browser instance, with a total of four instances: Yandex Browser 23 and three Chrome browsers. **Performance Comparison** The benchmark results show that: * Deque operations are significantly faster than Array deque operations * Dequeue operations on the Deque data structure outperform all other test cases * The order of browser instances does not affect the performance comparison between Deque, Array, and Queue Here is a summary of the top-performing test case for each data structure: | Data Structure | Test Case | ExecutionsPerSecond | | --- | --- | --- | | Deque | Dequeue (all) | 61.136112213134766 | | Array | Dequeue (all) | 34.13344955444336 | | Queue | Enqueue (all) | 20.14153480529785 | **Implications** The results of this benchmark test suggest that a Deque data structure is the most efficient choice for queue operations, followed closely by the Array data structure. The Queue data structure performs the worst in this comparison. These findings can be used to inform design decisions when selecting a queue data structure for specific use cases, particularly those involving frequent enqueue and dequeue operations.
Related benchmarks:
Map vs Map vs Foreach vs for
fill array with value: map(callback) vs fill(value)
iterating from a filled object VS iterating from a map
new Map vs set array to map
fill array with value: map(callback) vs fill(value) 2
Comments
Confirm delete:
Do you really want to delete benchmark?