If-Else Chain VS Switch(true)
JavaScript performance comparison
Info
This test is to attempt to determine if there is any notable performance difference when using switch(true) instead of a chain of if-else statements.
Preparation code
<script>
var strs = ['apple','banana','pear','lemon','grape','orange'], len = strs.length;
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
If-Else Chain |
|
pending… |
switch(true) |
|
pending… |
switch |
|
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 Jim
- Revision 2: published
- Revision 3: published
- Revision 4: published by Ben Truyman
- Revision 5: published
- Revision 6: published
- Revision 7: published
- Revision 8: published
- Revision 9: published by KDO
- Revision 11: published
0 comments