Condition VS RegExp VS indexOf
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
var a = 1,
b = 8;
var gTab = [1, 2, 3, 4, 5];
var gRg = /^1|2|3|4|5$/;
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Simple condition |
|
pending… |
indexOf |
|
pending… |
indexOf (not litteral) |
|
pending… |
RegExp |
|
pending… |
RegExp (not litteral) |
|
pending… |
RegExp (global) |
|
pending… |
indexOf (global) |
|
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:
- Revision 1: published by Nicolas Froidure
- Revision 2: published by Nicolas Froidure
- Revision 3: published by Nicolas Froidure
- Revision 4: published
0 comments