Dynamic regex creation vs storage

Benchmark created by lonesomeday on


Preparation HTML

<div id="Kees_1_test">test 1</div>
<div id="Kees_12_test">test 2</div>
<div id="Kees_335_test">test 3</div>
<div id="Kees_a_test">test 4</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
  var rkees = /Kees_\d+_test/;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Dynamic creation
$('div').filter(function() {
 return /Kees_\d+_test/.test(this.id);
});
ready
Cached
$('div').filter(function() {
 return rkees.test(this.id);
});
ready

Revisions

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

  • Revision 1: published by lonesomeday on