Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
string cast vs template literal cast vs cached empty string cast
(version: 1)
cast to string or template literal wrapping
Comparing performance of:
String literal vs Template literal vs Cast vs Cast cached string
Created:
4 months ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
/*your preparation JavaScript code goes here To execute async code during the script preparation, wrap it as function globalMeasureThatScriptPrepareFunction, example:*/ async function globalMeasureThatScriptPrepareFunction() { // This function is optional, feel free to remove it. // await someThing(); } const TEST_ITERATIONS=100000; const emptyString = '';
Tests:
String literal
/*When writing async/deferred tests, use `deferred.resolve()` to mark test as done*/ for (let i=0; i++; i<TEST_ITERATIONS) { const stringLiteral = String(i); }
Template literal
for (let i=0; i++; i<TEST_ITERATIONS) { const templateLiteral = `${i}` }
Cast
for (let i=0; i++; i<TEST_ITERATIONS) { const templateLiteral = '' + i; }
Cast cached string
for (let i=0; i++; i<TEST_ITERATIONS) { const templateLiteral = emptyString + i; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
String literal
Template literal
Cast
Cast cached string
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
4 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36
Browser/OS:
Chrome 143 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
String literal
274331136.0 Ops/sec
Template literal
254438832.0 Ops/sec
Cast
252651696.0 Ops/sec
Cast cached string
256002320.0 Ops/sec
Related benchmarks:
Nullish vs If
js mul vs pow
String literal vs Template literal assignment
test-string-1
Object vs Dictionary
string cast vs template literal cast
splice vs slice test
date.now
string cast vs template literal cast vs cached empty string cast with random values
Comments
Confirm delete:
Do you really want to delete benchmark?