Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Iterate / Loop over + Filter data-* attributes
(version: 1)
Comparing performance of:
Object.keys() + .dataset vs Array.from() + .attributes vs for + .attributes
Created:
one year ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<div id="div" data-foo="foo" data-bar="bar" data-baz="baz" data-test-a="a" data-test-b="b" data-test-c="c">
Script Preparation code:
let div = document.getElementById('div');
Tests:
Object.keys() + .dataset
Object.keys(div.dataset).filter(v => v.startsWith('test')).map(v => v.substring(4).toLowerCase());
Array.from() + .attributes
Array.from(div.attributes).map(a => a.nodeName).filter(v => v.startsWith('data-test-')).map(v => v.substring(10));
for + .attributes
let l = []; for(var i=0; i < div.attributes.length; i++) { let n = div.attributes[i].nodeName; if(n.startsWith('data-test-')) l.push(n.substring(10)); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Object.keys() + .dataset
Array.from() + .attributes
for + .attributes
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/130.0.0.0 Safari/537.36
Browser/OS:
Chrome 130 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Object.keys() + .dataset
955685.9 Ops/sec
Array.from() + .attributes
794734.0 Ops/sec
for + .attributes
1026422.6 Ops/sec
Related benchmarks:
non-unique-elements
non-unique-elements
Some vs Find vs Filter
for-in vs for-of
Filter vs Find vs Some
Some and Find
Test of 2.1
reduce vs plain cycle
Some vs Find2
Comments
Confirm delete:
Do you really want to delete benchmark?