-
-
Save Grassboy/05a6e815b8c010d64fa3e898b737a7b3 to your computer and use it in GitHub Desktop.
which_is_faster.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.time('p1'); | |
var data, n = 1000000; | |
for(var i = 0 ; i < n; i ++) data = { foo: 123, bar: i }; | |
console.timeEnd('p1'); | |
console.time('p2'); | |
for(var i = 0 ; i < n; i ++) data = JSON.parse("{\"foo\":123,\"bar\":"+i+"}"); | |
console.timeEnd('p2'); | |
//p1: 872ms - 計時器停止 | |
//p2: 1900ms - 計時器停止 | |
console.time('p1'); | |
var data, n = 1000000; | |
for(var i = 0 ; i < n; i ++) data = { foo: 123, bar: 456 }; | |
console.timeEnd('p1'); | |
console.time('p2'); | |
for(var i = 0 ; i < n; i ++) data = JSON.parse("{\"foo\":123,\"bar\":456}"); | |
console.timeEnd('p2'); | |
//p1: 718ms - 計時器停止 | |
//p2: 1299ms - 計時器停止 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment