Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
looped parsing
(version: 23)
Comparing performance of:
test1 vs test2 vs inlined
Created:
one year ago
by:
Registered User
Jump to the latest result
Script Preparation code:
let schema=[ //[0,0,0,8,4,15] "aaaiep", "" ] let P=(idx, view, buffer)=> { let sc = schema[idx]; let grandObject = []; let newObj = grandObject, decoder = new TextDecoder(), end_idx = sc.length, begin_idx = 0, repeats = 0, i = 0, offset = 0, rep_ct = 0; while (i < end_idx) { let field = sc.charCodeAt(i) - 0x61; let top = field >> 2; let code = field & 3; let candidate = 0; // don't read if its an end token... switch (code) { case 0:candidate=view.getInt8(offset,true);++offset;break; case 1:candidate=view.getInt16(offset,true);offset+=2;break; case 2:candidate=view.getInt32(offset,true);offset+=4;break; } if (top == 0) { newObj.push(candidate); } else if (top == 1) { newObj.push(decoder.decode(buffer.slice(offset, offset+candidate))); offset += candidate; } else if (top == 2) { repeats = candidate; rep_ct = 0; newObj.push(new Array(candidate).fill(null).map(() => [])); newObj = newObj.at(-1).at(0); begin_idx = i; } else { ++rep_ct; if (rep_ct >= repeats) { rep_ct = 0; newObj = grandObject; } else { i = begin_idx; newObj = grandObject.at(-1)[rep_ct]; } } ++i; } return grandObject;//[grandObject, offset]; } let arrData = [21, 19, 10, 5, 3, 97, 97 + 2, 97 + 5, 3, 97, 97 + 2, 97 + 5, 3, 97, 97 + 2, 97 + 5, 3, 97, 97 + 2, 97 + 5, 3, 97, 97 + 2, 97 + 5]; // Step 2: Create a Uint8Array from arrData let uint8Arr = new Uint8Array(arrData); // Step 3: Get the underlying ArrayBuffer from the Uint8Array let arrayBuf = uint8Arr.buffer; // Step 4: Create a DataView based on the ArrayBuffer let dataView = new DataView(arrayBuf); // Example usage: console.log(uint8Arr); // Uint8Array(7) [21, 19, 10, 3, 97, 99, 102] console.log(arrayBuf); // ArrayBuffer with byteLength of 7 console.log(dataView); // DataView { byteLength: 7, ... }
Tests:
test1
P(0,dataView, arrayBuf)
test2
const jsonStrings = [ '{"name": "Alice", "age": 30, "city": "Wonderland"}', '{"title": "Book Title", "author": "Some Author", "pages": 350}', '{"status": "success", "code": 50, "data": [1, 2, 3]}', '{"coordinates": {"x": 10, "y": 0}, "visible": true}', '{"items": ["apple", "banana", "ear"], "count": 3}', '{"status": "success", "code": 220, "data": [1, 2, 3]}', '{"coordinates": {"x": 10, "y": 10}, "visible": true}', '{"items": ["apple", "banana", "pear"], "count": 3}', '{"status": "success", "code": 3, "data": [1, 2, 3]}', '{"coordinates": {"x": 10, "y": 20}, "visible": true}', '{"items": ["apple", "banana", "pear"], "count": 3}', '{"status": "success", "code": 11, "data": [1, 2, 3]}', '{"coordinates": {"x": 10, "y": 20}, "visible": true}', '{"items": ["apple", "banana", "pear"], "count": 3}', '{"status": "success", "code": 4, "data": [1, 2, 3]}', '{"coordinates": {"x": 10, "y": 20}, "visible": true}', '{"items": ["apple", "banana", "pear"], "count": 3}', '{"status": "success", "code": 4, "data": [1, 2, 3]}', '{"coordinates": {"x": 10, "y": 5}, "visible": true}', '{"items": ["apple", "banana", "pear"], "count": 3}', '{"users": [{"id": 1}, {"id": 2}], "hasMore": false}' ]; // A function to pick a random JSON string from the array function getRandomJsonString() { // Generate a random index based on the length of the array const randomIndex = Math.floor(Math.random() * jsonStrings.length); // Return the JSON string at that index return jsonStrings[randomIndex]; } JSON.parse(getRandomJsonString());
inlined
let newObj=[],bytes = 0, decoder = new TextDecoder(); let ofs=0;dataView.getInt8(ofs,true);ofs+=1; dataView.getInt8(ofs,true);ofs+=1; dataView.getInt8(ofs,true);ofs+=1; let strlen=dataView.getInt8(ofs,true);ofs+=1; newObj.push(uint8Arr.subarray(ofs, ofs+strlen));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
test1
test2
inlined
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
Browser/OS:
Chrome 134 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
test1
300047.5 Ops/sec
test2
4842596.5 Ops/sec
inlined
3234919.0 Ops/sec
Related benchmarks:
className vs. classList (comparing and adding)8
className vs. classList (comparing and adding)1
Benchmark
className vs. classList v2
className vs. classList (comparing and adding)xxzczxccxzxcz
className vs classList add,remove
test12xxxx
test123v6
test123v7
Comments
Confirm delete:
Do you really want to delete benchmark?