Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36
Chrome 124
Mac OS X 10.15.7
Desktop
2 years ago
getElementsByClassName
625K/s
querySelectorAll with .class
398/s
querySelectorAll with [attribute]
204/s
filter with className
69/s
filter with getAttribute
45/s
filter with classList
33/s
for with className
18/s
for with classList
16/s
for with getAttribute
14/s
View exact numbers
Test name Executions per second
getElementsByClassName 625,272 Ops/sec
querySelectorAll with .class 398 Ops/sec
querySelectorAll with [attribute] 204 Ops/sec
filter with className 69 Ops/sec
filter with getAttribute 45 Ops/sec
filter with classList 33 Ops/sec
for with className 18 Ops/sec
for with classList 16 Ops/sec
for with getAttribute 14 Ops/sec
HTML Preparation code:
Script Preparation code:
Tests: