DEV Community

Discussion on: 4 Ways to Combine Strings in JavaScript

Collapse
 
functional_js profile image
Functional Javascript • Edited

Great work Samantha.

Performance Test


const icon = 'πŸ‘‹';

timeInLoop("template literal", 1e6, () => `hi ${icon}`);

timeInLoop("plus operator", 1e6, () => "hi " + icon);

timeInLoop("concat func", 1e6, () => ''.concat('hi ', icon));

timeInLoop("arr join", 1e6, () => ['hi', icon].join(' '));

/*
@perftests
run 1 million times each

template literal: 1e+6:     14.575ms
plus operator:    1e+6:     53.776ms
concat func:      1e+6:     391.723ms
arr join:         1e+6:     681.97ms

*/

Source Code for timeInLoop func

gist.github.com/funfunction/91b587...

Collapse
 
samanthaming profile image
Samantha Ming

Great! thanks for the performance test πŸ‘