Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Attribute Parser 2
(version: 0)
1 large object-attribute v. smaller attributes
Comparing performance of:
Atomic Parser vs Piecemeal Parser
Created:
2 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<div class="main"></div>
Script Preparation code:
const largeTemplate = `<div class="large" data-options="{"smSlowUrl":"https://kstatic.googleusercontent.com/files/35f440ff890c6189ae31c65dd8471dc64cc11c2b7e155980a1905b22e0d1efff89de049d0907d05f8967ec1e54dea7d7febe1327d70ac8f35bb8d17a059fcaf2","smFastUrl":"https://kstatic.googleusercontent.com/files/c535a43e6fa85b3fd539a235907e8dd385aa19a62094ad815a1679aa34a0129bea2c4c570217e9ff11c884bffed237e2dd75954fd91be1a1bdd44e4ca4256999","lgSlowUrl":"https://kstatic.googleusercontent.com/files/c146fa9200c5a4e4be6ea7d0586bc2c566d8c26d31523e778fee3b17adf078470e28924f107ff7a5cb6e83a67ce804b8dcdb23a54080b4445d5b03ae5d407c5a","lgFastUrl":"https://kstatic.googleusercontent.com/files/f27e919a897b995d58ff3aa0717f09a756c09941362324208bde96c89c3f1fedb14bd70d7a3ea11f64b65b3409f78fa2b4c7b679f3d1c7f8f31576ef563f21a9","pauseLabel":"Pause hero football video","playLabel":"Play hero football video"}">Large</div>`; const smallTemplate = `<div class="small" data-a="["foo", "bar", "blah"]" data-b="https://kstatic.googleusercontent.com/files/c535a43e6fa85b3fd539a235907e8dd385aa19a62094ad815a1679aa34a0129bea2c4c570217e9ff11c884bffed237e2dd75954fd91be1a1bdd44e4ca4256999" data-c="https://kstatic.googleusercontent.com/files/c146fa9200c5a4e4be6ea7d0586bc2c566d8c26d31523e778fee3b17adf078470e28924f107ff7a5cb6e83a67ce804b8dcdb23a54080b4445d5b03ae5d407c5a" data-d="https://kstatic.googleusercontent.com/files/f27e919a897b995d58ff3aa0717f09a756c09941362324208bde96c89c3f1fedb14bd70d7a3ea11f64b65b3409f78fa2b4c7b679f3d1c7f8f31576ef563f21a9" data-e="Pause hero football video" date-f="Play hero football video&">Small</div>`; let i = 1000; const root = document.querySelector('.main'); while (i--) { root.innerHTML += largeTemplate; root.innerHTML += smallTemplate; }
Tests:
Atomic Parser
const largeNodes = Array.from(document.querySelectorAll('.large')); largeNodes.map((node) => { const options = node.getAttribute('data-options'); return JSON.parse(options); });
Piecemeal Parser
const smallNodes = Array.from(document.querySelectorAll('.small')); smallNodes.map((node) => { const data = node.dataset; const a = JSON.parse(data.a); const b = '' + data.b; const c = '' + data.c; const d = '' + data.d; const e = '' + data.e; const f = '' + data.f; return {a, b, c, d, e, f}; });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Atomic Parser
Piecemeal Parser
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36
Browser/OS:
Chrome 122 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Atomic Parser
1084.8 Ops/sec
Piecemeal Parser
1269.6 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into explaining the benchmark test. **Benchmark Definition:** The benchmark is designed to measure the performance of two different approaches to parse attribute data from HTML elements. The test case consists of two parts: 1. **Atomic Parser:** This approach uses the `getAttribute` method to retrieve the `data-options` attribute from each `.large` element, and then parses the resulting string as JSON using `JSON.parse`. 2. **Piecemeal Parser:** This approach uses the `dataset` property to access individual attributes (e.g., `a`, `b`, `c`, etc.) directly from each `.small` element, without needing to concatenate them into a single string. **Options Compared:** The two approaches differ in how they process attribute data: 1. **Atomic Parser:** This approach: * Uses the `getAttribute` method to retrieve the entire `data-options` attribute as a single string. * Parses this string as JSON using `JSON.parse`. 2. **Piecemeal Parser:** This approach: * Uses the `dataset` property to access individual attributes (e.g., `a`, `b`, etc.) directly from each element. * Converts these attribute values into JavaScript variables (e.g., `const a = data.a;`) and returns an object with all the properties. **Pros and Cons:** 1. **Atomic Parser:** + Pros: - Simplifies parsing logic, as it only needs to handle one JSON string. - Could be more efficient if the attribute data is large and doesn't fit in a single JavaScript variable. * Cons: - Requires concatenating multiple attributes into a single string, which might lead to performance issues for large datasets. - Needs to handle JSON parsing errors, which can slow down execution. 2. **Piecemeal Parser:** + Pros: - Can process individual attributes more efficiently, as they don't need to be concatenated or parsed into a single string. - Reduces the risk of parsing errors, as each attribute is processed individually. * Cons: - Requires accessing and processing multiple dataset properties, which might increase overhead for larger datasets. **Library Usage:** None of the provided benchmark definitions explicitly use any external libraries. However, it's worth noting that `JSON.parse()` relies on the built-in JSON parsing functionality in JavaScript engines. **Special JS Features/Syntax:** No special JavaScript features or syntax are used in these benchmark definitions. The code is straightforward and follows standard JavaScript practices. **Other Alternatives:** If this benchmark were to be modified or expanded, alternative approaches might include: 1. **Using a dedicated attribute parser library**, which could provide optimized parsing logic for specific use cases. 2. **Implementing a custom parsing function**, tailored to the specific requirements of the attribute data (e.g., handling specific attribute types or formats). 3. **Exploring other data processing techniques**, such as using a streaming approach to process attribute data in real-time. By understanding these differences and trade-offs, developers can better choose between various approaches for parsing attribute data in their own projects.
Related benchmarks:
Lodash pick vs manual object descturct6
Lodash.get vs native [Krosnoz]
JavaScript sfsdfsdf performance1
Attribute Parser l
Comments
Confirm delete:
Do you really want to delete benchmark?