Run details:
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
Chrome 122
Mac OS X 10.15.7
Desktop
2 years ago
getElementsByClassName
1.6M/s
querySelectorAll with .class
480/s
querySelectorAll with [attribute]
185/s
filter with className
90/s
filter with getAttribute
57/s
filter with classList
37/s
for with className
36/s
for with getAttribute
31/s
for with classList
24/s
View exact numbers
Test name Executions per second
getElementsByClassName 1,588,381 Ops/sec
querySelectorAll with .class 480 Ops/sec
querySelectorAll with [attribute] 185 Ops/sec
filter with className 90 Ops/sec
filter with getAttribute 57 Ops/sec
filter with classList 37 Ops/sec
for with className 36 Ops/sec
for with getAttribute 31 Ops/sec
for with classList 24 Ops/sec
HTML Preparation code:
Script Preparation code:
Tests: