Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
dataset
(version: 0)
Banchmark dataset with string vs direct
Comparing performance of:
direct vs with string
Created:
3 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<div id='test' class="test" data-test='test'></div>
Script Preparation code:
var el = document.getElementById('test')
Tests:
direct
el.dataset.test;
with string
el.dataset['test'];
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
direct
with string
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Browser/OS:
Chrome 131 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
direct
12840927.0 Ops/sec
with string
12786073.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the benchmark and explain what's being tested, compared, and some pros/cons of different approaches. **Benchmark Overview** The benchmark is designed to compare two ways of accessing a dataset property in JavaScript: using the dot notation (`el.dataset.test;`) and using the bracket notation with a string (`el.dataset['test'];`). **What's Being Tested?** In this benchmark, we have two individual test cases: 1. **Direct**: `el.dataset.test;` 2. **With String**: `el.dataset['test'];` Both tests measure the performance of accessing a dataset property using the specified syntax. **Comparison Options** The comparison options are: * Dot notation (`el.dataset.test;`) * Bracket notation with a string (`el.dataset['test'];`) **Pros and Cons** ### Dot Notation Pros: * Typically faster and more readable * Less error-prone, as it's harder to accidentally access the wrong property using the dot notation Cons: * May not work in older browsers that don't support dataset attributes (although this is unlikely with modern browsers) * Can be less flexible if you need to use a dynamic property name ### Bracket Notation with String Pros: * More flexible, as it can be used with both string and non-string values * Works in older browsers that don't support dataset attributes Cons: * Typically slower due to the overhead of using a bracket notation * Can lead to typos or other errors if not used carefully (e.g., accessing `el.dataset['test']` instead of `el.dataset.test;`) **Library and Purpose** In this benchmark, we don't see any specific JavaScript library being used. However, it's likely that the dataset attribute is a modern web feature that's supported by most browsers. If you're interested in exploring other alternatives or libraries, here are some options: * For accessing dataset attributes, consider using a library like `dataset-attribute` (a polyfill for older browsers). * For benchmarking JavaScript performance, consider using a tool like WebPageTest or BenchmarkJS. * For testing specific JavaScript features or syntax, consider using a tool like JSLint or ESLint. **Special JS Feature** There isn't any special JS feature being tested in this benchmark. The comparison is focused on the syntax for accessing dataset attributes. Let me know if you have any further questions!
Related benchmarks:
dataset access
getAttribute('data-foo') vs dataset.foo
Check data attribute: hasAttribute vs dataset
dataset vs textContent
Comments
Confirm delete:
Do you really want to delete benchmark?