filter() vs multiple expressions

JavaScript performance comparison

Test case created by vzwick

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<select name="options[0][option_group_id]" />
<select name="options[1][option_group_id]" />
<select name="options[2][option_group_id]" />
<select name="options[new3][option_group_id]" />

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
filter()
var pattern = /options\[\d{1,}\]\[option_group_id\]/;
var $collection = $('select').filter(function() {
  return $(this).attr('name').match(pattern) !== null;
});
pending…
Multiple Expressions
var $collection = $('select[name^="options"][name$="[option_group_id]"]');
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 comments

Add a comment