Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Queue comparison
(version: 0)
Comparing performance of:
array vs queue vs array non-destructive vs queue2
Created:
6 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
function QueueItem(value) { this.value = value; this.next = void 0; } function Queue() { this.first = void 0; this.last = void 0; } Queue.prototype.enqueue = function (value) { var wasEmpty = !this.first; var item = new QueueItem(value); if (wasEmpty) { this.first = item; } else { this.last.next = item; } this.last = item; return wasEmpty; }; Queue.prototype.dequeue = function () { var first = this.first; if (first) { this.first = first.next; } if (first === this.last) { this.last = void 0; } return first.value; }; Queue.prototype.isEmpty = function () { return !this.first; }; var a = []; var q = new Queue(); class Queue2 { constructor() { this.list = new Set(); } enqueue(value) { this.list.add({value}); } dequeue() { for (let item of this.list) { this.list.delete(item); return item.value; } } isEmpty() { return this.list.size === 0; } } var q2 = new Queue2();
Tests:
array
for (var i = 0; i < 100; i++) { a.push(i); } while (a.length) { var x = a.shift(); }
queue
for (var i = 0; i < 100; i++) { q.enqueue(i); } while (!q.isEmpty()) { var x = q.dequeue(); }
array non-destructive
for (var i = 0; i < 100; i++) { a.push(i); } for (var i = 0, len = a.length; i < len; i++) { var x = a[i]; } a = [];
queue2
for (var i = 0; i < 100; i++) { q2.enqueue(i); } while (!q2.isEmpty()) { var x = q2.dequeue(); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
array
queue
array non-destructive
queue2
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one month ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36
Browser/OS:
Chrome 146 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
array
600875.6 Ops/sec
queue
843725.6 Ops/sec
array non-destructive
1426248.6 Ops/sec
queue2
122065.9 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what's being tested. **Benchmark Definition** The benchmark definition is a set of JavaScript code snippets that measure the performance of different approaches to achieving a specific goal. In this case, there are four test cases: 1. `array`: Measures the time it takes to perform an array push followed by a while loop removing elements from the end of the array. 2. `queue`: Measures the time it takes to enqueue and dequeue elements from a queue data structure. 3. `array non-destructive`: Measures the time it takes to iterate over an array without modifying its contents, then reset the array to an empty state. 4. `queue2`: Similar to `queue`, but uses a different implementation of a queue. **What's being tested** Each test case is designed to measure the performance of a specific algorithm or data structure: * `array` and `queue` tests measure the performance of basic operations on arrays and queues, such as pushing/enqueuing elements and removing/dequeueing elements. * `array non-destructive` tests measure the performance of iterating over an array without modifying its contents. * `queue2` tests measure the performance of a specific implementation of a queue data structure. **Options compared** The benchmark compares different approaches to achieving the same goal: * For arrays, there's no comparison between different approaches (e.g., using `push`, `unshift`, or iterating over the array). * For queues, there are two implementations (`queue` and `queue2`) that are being compared. * For arrays, only a single iteration is performed, which doesn't provide much insight into the performance of different algorithms. **Pros and Cons** Here are some pros and cons for each test case: * `array`: This test case provides a basic understanding of how arrays perform in terms of push, remove, and loop operations. However, it's limited by only measuring one specific operation. * `queue`: By comparing two implementations, this test case provides insight into the performance differences between them. However, the results may be biased towards the implementation being tested (e.g., if `queue2` is optimized for performance). * `array non-destructive`: This test case highlights the performance implications of iterating over an array without modifying its contents. It's a useful benchmark for understanding the overhead of such operations. **Library usage** There are no libraries used in this benchmark that affect the results, other than the standard JavaScript arrays and queue data structures. **Special JS features or syntax** No special JavaScript features or syntax are being tested in this benchmark. The focus is on measuring the performance of basic array and queue operations. **Other alternatives** If you want to explore alternative approaches for similar benchmarks, here are some ideas: * For array operations: + Measuring the performance of different data structures (e.g., linked lists, trees) for storing and retrieving elements. + Comparing the performance of different algorithms for searching or sorting arrays. * For queue operations: + Using a different programming language (e.g., Python, Java) to measure the performance differences in queue operations. + Exploring the performance of different queue data structures (e.g., linked lists, circular buffers). Keep in mind that these alternative approaches may not be directly comparable to the original benchmark, and new tests would need to be designed to account for any differences in language or framework.
Related benchmarks:
Queue comparison4
Queue data structure
Linked List Queue vs Double Array Queue vs Queue with Map v3
Linked List Queue vs Double Array Queue vs Queue with Map enqueue/dequeue/dequeueTail
Comments
Confirm delete:
Do you really want to delete benchmark?