Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Array vs Linked List App
Array vs Linked List App
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Browser:
Chrome 131
Operating system:
Linux
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Linked List
153.4 Ops/sec
Array
131.1 Ops/sec
HTML Preparation code:
<ul id="request-list"> </ul>
Script Preparation code:
/** * Convenience method to create nodes * @param data * @param next * @return {{data: *, next: *}} */ function createNode(data, next) { return { data: data, next }; } /** * Determines whether or not the list is empty * @param head * @return {boolean} */ function isEmptyList(head) { return head === null; } /** * Linked List base on code by Nicholas C Zakas. Additional modifications are my own. */ function LinkedList() { this._size = 0; this._head = null; this._tail = null; } LinkedList.prototype = { //restore constructor constructor: LinkedList, /** * Like its array counterpart, unshift appends an item to the beginning of the list * @param data */ unshift: function unshift(data) { const node = createNode(data); //special case: no items in the list yet if (isEmptyList(this._head)) { this._head = node; } else { node.next = this._head; this._head = node; } ++this._size; }, /** * Returns the size of the list * @return {number} */ size: function size() { return this._size; }, /** * Applies a function to each item in the list * @param fn */ forEach: function forEach(fn) { if (this._size > 0) { let current = this._head; let index = 0; while (current) { fn(current.data, index, this); ++index; current = current.next; } } } } function domUpdater(requestList) { let batch = document.createDocumentFragment(); const list = document.getElementById("request-list"); requestList.forEach(function(request) { const li = document.createElement("li"); li.dataset.id = request.id; li.textContent = request.details; batch.appendChild(li); }); list.appendChild(batch); } function createRequest(num) { return { id: num, details: "details for: " + num }; }
Tests:
Linked List
const requests = new LinkedList(); let count = 500; while(count--) { requests.unshift(createRequest(count)); } domUpdater(requests);
Array
const requests = []; let count = 500; while(count--) { requests.unshift(createRequest(count)); } domUpdater(requests);