hasClass with className.match
JavaScript performance comparison
Preparation code
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div id="test" class="bar foo baz">test wrapper</div>
<script>
Benchmark.prototype.setup = function() {
var test = document.getElementById( 'test' ),
$test = $( '#test' );
var myHasClass = function( toTest, obj ) {
return obj[0].className.match( new RegExp( '\\b' + toTest + '\\b', 'g' ) );
};
};
</script>
Preparation code output
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
jQuery hasClass |
|
pending… |
className match RegExp |
|
pending… |
native |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments