Skip to content

Instantly share code, notes, and snippets.

@komayuki
Last active May 30, 2017 06:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save komayuki/59a3e22cff470c83c169219bc29651fd to your computer and use it in GitHub Desktop.
Save komayuki/59a3e22cff470c83c169219bc29651fd to your computer and use it in GitHub Desktop.
String(10) VS 10 + ''

Speed test Javascript code

String(int) VS 10 + ''

Code

const list = []
const startTime = new Date();
for(let i = 0; i < 10000000; i++){
  // list.push(i + '')
  list.push(String(i))                                                      
}           
const endTime = new Date();             
console.log(endTime - startTime + 'ms')

measurements

int + '' String(int)
1 1342ms 1390ms
2 1353ms 1365ms
3 1331ms 1423ms
4   1366ms         1413ms
5   1356ms         1417ms
6     1500ms         1434ms
7     1437ms         1426ms
8     1421ms         1479ms
9     1485ms         1389ms
10    1429ms         1455ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment