Impact of string conversion on a string
JavaScript performance comparison
Info
In this test case, I check whether which way of converting any input to a string for type safety reason has the least impact on the performance in case a string is passed as argument.
Preparation code
<script>
Benchmark.prototype.setup = function() {
window.a = function a(s) {
return String(s).length;
}
window.b = function b(s) {
return (""+s).length;
}
window.c = function a(s) {
return String(s).length;
}
window.d = function b(s) {
return (""+s).length;
}
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
String function |
|
pending… |
Empty string concatenation |
|
pending… |
String function* |
|
pending… |
Empty string concatenation* |
|
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 François REMY
- Revision 2: published by François REMY
0 comments