Last active
October 12, 2017 12:44
-
-
Save legraphista/d706e5c31b3080e3773a1960c08e8306 to your computer and use it in GitHub Desktop.
test for fast cloning of objects
This file contains hidden or 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
var fastDeepclone = require("fast-deepclone"); | |
var FastClone = require("fastest-clone"); | |
const arr = 'x'.repeat(10000).split('').map(_ => ({ | |
a: 2, | |
b: { c: 1, d: { e: { f: { g: 5 } } } } | |
})); | |
for (let i = 0; i < 10; i++) { | |
console.time('fastest-clone SINGLE x10000'); | |
for (let i = 0; i < 10000; i++) { | |
const x = FastClone.cloneArray([ { a: 2 } ], true)[ 0 ]; | |
} | |
console.timeEnd('fastest-clone SINGLE x10000'); | |
console.time('fastest-clone ARRAY(10000)'); | |
FastClone.cloneArray(arr, true); | |
console.timeEnd('fastest-clone ARRAY(10000)'); | |
console.time('fast-deepclone SINGLE x10000'); | |
for (let i = 0; i < 10000; i++) { | |
const x = fastDeepclone({ a: 2 }); | |
} | |
console.timeEnd('fast-deepclone SINGLE x10000'); | |
console.time('fast-deepclone ARRAY(10000)'); | |
const x = fastDeepclone(arr); | |
console.timeEnd('fast-deepclone ARRAY(10000)'); | |
console.time('JSON SINGLE x10000'); | |
for (let i = 0; i < 10000; i++) { | |
const x = JSON.parse(JSON.stringify({ a: 2 })); | |
} | |
console.timeEnd('JSON SINGLE x10000'); | |
console.time('JSON ARRAY(10000)'); | |
JSON.parse(JSON.stringify(arr)); | |
console.timeEnd('JSON ARRAY(10000)'); | |
console.log('~'.repeat(80)); | |
} |
This file contains hidden or 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
fastest-clone SINGLE x10000: 51.541ms | |
fastest-clone ARRAY(10000): 5.078ms | |
fast-deepclone SINGLE x10000: 15.998ms | |
fast-deepclone ARRAY(10000): 99.078ms | |
JSON SINGLE x10000: 11.605ms | |
JSON ARRAY(10000): 30.400ms | |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
fastest-clone SINGLE x10000: 65.647ms | |
fastest-clone ARRAY(10000): 3.466ms | |
fast-deepclone SINGLE x10000: 15.829ms | |
fast-deepclone ARRAY(10000): 72.650ms | |
JSON SINGLE x10000: 16.246ms | |
JSON ARRAY(10000): 21.023ms | |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
fastest-clone SINGLE x10000: 44.969ms | |
fastest-clone ARRAY(10000): 2.095ms | |
fast-deepclone SINGLE x10000: 20.088ms | |
fast-deepclone ARRAY(10000): 76.063ms | |
JSON SINGLE x10000: 6.357ms | |
JSON ARRAY(10000): 20.863ms | |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
fastest-clone SINGLE x10000: 40.331ms | |
fastest-clone ARRAY(10000): 7.933ms | |
fast-deepclone SINGLE x10000: 12.039ms | |
fast-deepclone ARRAY(10000): 92.510ms | |
JSON SINGLE x10000: 6.393ms | |
JSON ARRAY(10000): 20.875ms | |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
fastest-clone SINGLE x10000: 38.742ms | |
fastest-clone ARRAY(10000): 2.148ms | |
fast-deepclone SINGLE x10000: 14.438ms | |
fast-deepclone ARRAY(10000): 68.346ms | |
JSON SINGLE x10000: 6.720ms | |
JSON ARRAY(10000): 20.872ms | |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
fastest-clone SINGLE x10000: 38.047ms | |
fastest-clone ARRAY(10000): 2.756ms | |
fast-deepclone SINGLE x10000: 11.328ms | |
fast-deepclone ARRAY(10000): 78.000ms | |
JSON SINGLE x10000: 6.362ms | |
JSON ARRAY(10000): 21.123ms | |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
fastest-clone SINGLE x10000: 48.383ms | |
fastest-clone ARRAY(10000): 4.475ms | |
fast-deepclone SINGLE x10000: 21.040ms | |
fast-deepclone ARRAY(10000): 75.319ms | |
JSON SINGLE x10000: 6.481ms | |
JSON ARRAY(10000): 19.148ms | |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
fastest-clone SINGLE x10000: 36.431ms | |
fastest-clone ARRAY(10000): 2.117ms | |
fast-deepclone SINGLE x10000: 10.694ms | |
fast-deepclone ARRAY(10000): 76.410ms | |
JSON SINGLE x10000: 6.039ms | |
JSON ARRAY(10000): 28.506ms | |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
fastest-clone SINGLE x10000: 37.697ms | |
fastest-clone ARRAY(10000): 1.865ms | |
fast-deepclone SINGLE x10000: 10.297ms | |
fast-deepclone ARRAY(10000): 74.561ms | |
JSON SINGLE x10000: 6.136ms | |
JSON ARRAY(10000): 24.182ms | |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
fastest-clone SINGLE x10000: 42.572ms | |
fastest-clone ARRAY(10000): 2.220ms | |
fast-deepclone SINGLE x10000: 14.325ms | |
fast-deepclone ARRAY(10000): 73.416ms | |
JSON SINGLE x10000: 6.400ms | |
JSON ARRAY(10000): 20.029ms | |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment