Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
looped parsing
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36
Browser:
Chrome 132
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
test1
4423763.0 Ops/sec
test2
4663258.0 Ops/sec
inlined
1391944.4 Ops/sec
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));