id regex vs class

JavaScript performance comparison

Test case created by Gromer

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

<input id="txtName1" name="txtName1" class="jName" type="text" />
<input id="txtName2" name="txtName2" class="jName" type="text" />
<input id="txtName3" name="txtName3" class="jName" type="text" />
<input id="txtName4" name="txtName4" class="jName" type="text" />
<input id="txtName5" name="txtName5" class="jName" type="text" />

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
id regex
var matches = $('input[id^="txtName"]');
pending…
class
var matches = $('.jName');
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment