Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Read/Write cycle for fixed size array
(version: 0)
10 writes per 1 read
Comparing performance of:
slice immutable vs splice immutable vs shift-while immutable vs slice mutable vs splice mutable vs shift-while mutable vs circular buffer
Created:
5 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var count = 120000; var list = new Array(count).fill(100);
Tests:
slice immutable
var insertCount = 0; for (var i = 0; i < 10; ++i) { if (list.length > count - 1) { list=list.slice(0, count - 1) list.push(insertCount++) } else { list = [...list, insertCount++]; } } var foo = list;
splice immutable
var insertCount = 0; for (var i = 0; i < 10; ++i) { list = [...list, insertCount++] if (list.length > count) { list.splice(0, list.length - count); } } var foo = list;
shift-while immutable
var insertCount = 0; for (var i = 0; i < 10; ++i) { list = [...list, insertCount++] while (list.length > count) { list.shift(); } } var foo = list;
slice mutable
var insertCount = 0; for (var i = 0; i < 10; ++i) { list=list.slice(0, count) list.push(insertCount++) } var foo = list;
splice mutable
var insertCount = 0; for (var i = 0; i < 10; ++i) { list.push(insertCount++) if (list.length > count) { list.splice(0, list.length - count); } } var foo = list;
shift-while mutable
var insertCount = 0; for (var i = 0; i < 10; ++i) { list.push(insertCount++) while (list.length > count) { list.shift(); } } var foo = list;
circular buffer
var idx = 0; var insertCount = 0; for (var i = 0; i < 10; ++i) { list[idx] = insertCount++; idx = (idx + 1) % count; } var foo = [...list.slice(idx), ...list.slice(0, idx)];
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (7)
Previous results
Fork
Test case name
Result
slice immutable
splice immutable
shift-while immutable
slice mutable
splice mutable
shift-while mutable
circular buffer
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!
Related benchmarks:
using .length within and out of for loop
Performance of JavaScript .forEach, for in
Performance of JavaScript .forEach, for in v3
Array fill map, vs for i loop
Array fill map, vs while loop
Comments
Confirm delete:
Do you really want to delete benchmark?