Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
FAQ
Register
Log In
Check if an element contains a class name using a regular expression
(version: 0)
Benchmark.js
Comparing performance of:
loop vs className
Created:
3 years ago
by:
Guest
Go to the latest result
HTML Preparation code:
<div class='one two three four five six seven eight nine testClass hello_world' id='demoBlock'></div>
Script Preparation code:
var el = document.getElementById('demoBlock');
Tests:
loop
for (var i=0, l=el.classList.length; i<l; ++i) { if(/hello_[^\s]+/.test(el.classList[i])) { console.log('found') break; } }
className
if (/hello_[^\s]+/.test(el.className)) { console.log('found') }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
loop
className
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36
Browser/OS:
Chrome 130 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
className
180K/s
loop
103K/s
View exact numbers
Test name
Executions per second
✓
className
180,467 Ops/sec
loop
102,862 Ops/sec
Related benchmarks
classList.contains vs. loop vs regex
classList.contains vs. Set vs regex
Comments
Confirm delete:
Do you really want to delete benchmark?