Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Queue Implement by 2 Stacks
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/120.0.0.0 Whale/3.5.4.2 Safari/537.36
Browser:
Chrome 120
Operating system:
Linux
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Array
5.1 Ops/sec
Queue with 2 Stacks
232.0 Ops/sec
Ring Buffer
310.9 Ops/sec
Ring Buffer (Int32Array)
416.9 Ops/sec
(FYI) Rust + wasm
1590.5 Ops/sec
HTML Preparation code:
<script> (async () => { const importObject = { imports: { } }; const ex = 'https://unpkg.com/@wass80/wasm-queue@0.2.2/wasm_queue_bg.wasm'; const wasm_obj = await WebAssembly.instantiateStreaming(fetch(ex), importObject); const wasm = wasm_obj.instance.exports; window.wasm_zigzag = wasm.zigzag })(); </script>
Script Preparation code:
window.zigzag = (n, init, shift, push)=>{ let seed = 12345; let size = 0; let last = -1; for (let i = 0; i < n; i++) { if (size > 0 && (seed & 20480) == 0) { // 2^12+2^14=20480 last = shift(init); size--; } else { push(init,seed); size++; } seed = (seed * 1664525 + 1013904223) & 2147483647; } if (last !== 1508974062) alert("Assertion Failed!"); } // 2 Stack window.stack_shift = x=>{ if (x[0].length == 0){ x[0] = x[1]; x[1] = []; x[0].reverse(); } return x[0].pop(); } window.stack_push = (x,v)=>{ x[1].push(v); } // Ring Buffer window.ring_shift = (a) => { const res = a.data[a.head]; a.head = (a.head + 1) % a.data.length; return res; } window.ring_push = (a,v)=>{ a.data[a.tail] = v; a.tail = (a.tail + 1) % a.data.length; } window.ring_init = (r) => {return {data: new Array(r), head:0, tail: 0}}; window.int32array_init = (r) => {return {data: new Int32Array(r), head:0, tail: 0}}; window.n = 100000;
Tests:
Array
zigzag(n, [], a=>a.shift(), (a,v)=>a.push(v))
Queue with 2 Stacks
zigzag(n, [[],[]], stack_shift, stack_push)
Ring Buffer
zigzag(n, ring_init(n), ring_shift, ring_push)
Ring Buffer (Int32Array)
zigzag(n, int32array_init(n), ring_shift, ring_push)
(FYI) Rust + wasm
last = window.wasm_zigzag(n); if (last !== 1508974062) alert("Assertion Failed!");