contains() vs indexOf
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
'use strict';
if (!String.prototype.contains) {
String.prototype.contains = function(searchString) {
return this.indexOf(searchString) !== -1;
};
}
var string = 'foobarfoobar';
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
Test | Ops/sec | |
---|---|---|
<
|
|
pending… |
indexOf
|
|
pending… |
contains
|
|
pending… |
~string.indexOf
|
|
pending… |
!==
|
|
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.
- Revision 1: published
- Revision 2: published RubaXa
- Revision 3: published
- Revision 4: published
- Revision 5: published termi
- Revision 6: published
- Revision 7: published test
- Revision 8: published
- Revision 9: published
- Revision 10: published
- Revision 12: published
- Revision 13: published ES
- Revision 14: published
- Revision 15: published Baruch
- Revision 16: published Connor
- Revision 17: published gandalf
- Revision 18: published
0 Comments