querySelectorAll with .class vs querySelectorAll with [attribute] vs filter with classList vs filter with className vs filter with getAttribute vs for with classList vs for with className vs for with getAttribute vs getElementsByClassNameFastest: getElementsByClassName (42144.7x faster)
2,562,338 ops/sec
549 ops/sec
318 ops/sec
128 ops/sec
89 ops/sec
80 ops/sec
67 ops/sec
62 ops/sec
61 ops/sec
Results show median performance across all community submissions. Run this benchmark yourself to verify on your device.
| Test case name | Result |
|---|---|
| querySelectorAll with .class | |
| querySelectorAll with [attribute] | |
| filter with classList | |
| filter with className | |
| filter with getAttribute | |
| for with classList | |
| for with className | |
| for with getAttribute | |
| getElementsByClassName |
| Test name | Executions per second |
|---|---|
| ✓ getElementsByClassName | 2,704,543 Ops/sec |
| querySelectorAll with .class | 496 Ops/sec |
| querySelectorAll with [attribute] | 353 Ops/sec |
| for with className | 136 Ops/sec |
| filter with className | 125 Ops/sec |
| for with getAttribute | 95 Ops/sec |
| filter with getAttribute | 91 Ops/sec |
| filter with classList | 70 Ops/sec |
| for with classList | 69 Ops/sec |