Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Linked List Queue vs Double Array Queue vs Queue with Map v2
(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:
function createLinkedListQueue() { let length = 0 let head = undefined let tail = undefined return { enqueue(value) { enqueueNode(value) }, dequeue() { return dequeueNode() }, size() { return length }, head() { return head }, tail() { return tail } } function enqueueNode(value) { const node = { value, next: undefined } if(!head) { head = node tail = node } else { tail.next = node tail = node } length += 1 } function dequeueNode() { if(head) { const value = head.value head = head.next length -= 1 return value } tail = undefined return undefined } } function createDoubleArrayQueue() { return { input: [], 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 = createDoubleArrayQueue() var linkedListQ = createLinkedListQueue() 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):
**Overview of the Benchmark** The provided JSON represents a JavaScript benchmarking test, specifically designed to compare the performance of three different queue data structures: 1. Linked List Queue 2. Double Array Queue 3. Queue with Map (using the built-in `Map` object in JavaScript) The test consists of six individual test cases, each measuring the execution time for a specific operation: * Enqueuing an element into the queue * Dequeuing an element from the queue **What is being tested?** In essence, this benchmark is testing the performance of different data structures for inserting and removing elements. The results will provide insight into which data structure is most efficient in terms of execution time. **The Data Structures** 1. **Linked List Queue**: A simple queue implemented using a linked list. 2. **Double Array Queue**: A queue implemented using an array, with each element being wrapped in an object to avoid indexing issues. 3. **Queue with Map**: A queue implemented using the built-in `Map` object in JavaScript, which provides efficient insertion and deletion operations. **The Test Cases** Each test case consists of a single operation: * Enqueuing an element into the queue * Dequeuing an element from the queue The results are reported in terms of **ExecutionsPerSecond**, which represents the number of executions per second for each test case. **Interpretation of Results** By comparing the execution times across different data structures, we can infer: * Which data structure is most efficient in terms of execution time. * Whether the use of a built-in data structure (e.g., `Map`) provides significant performance benefits over custom implementations. In this specific benchmark, the results suggest that the **Queue with Map** implementation is the fastest for both enqueuing and dequeuing operations. The Linked List Queue and Double Array Queue implementations are significantly slower.
Related benchmarks:
array vs hashmap vs array-polling
iterating from a filled object VS iterating from a map
Map vs Array vs Object vs Set add item speed in 50000 iters 2
Array deconstruction vs array push
new Map vs set array to map
Comments
Confirm delete:
Do you really want to delete benchmark?