Object cloning

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
strcuturedClone
let i = 1000,
 arr = [],
 obj = {test:"me","test2":"metoo"};

while(i){
	i--;
	let clone = structuredClone(obj);
	arr.push(clone);
}
ready
rest constructor
let i = 1000,
 arr = [],
 obj = {test:"me","test2":"metoo"};

while(i){
	i--;
	let clone = {...obj};
	arr.push(clone);
}
ready
object assign
let i = 1000,
 arr = [],
 obj = {test:"me","test2":"metoo"};

while(i){
	i--;
	let clone = Object.assign({},obj);
	arr.push(clone);
}
ready
JSON stringify
let i = 1000,
 arr = [],
 obj = {test:"me","test2":"metoo"};

while(i){
	i--;
	let clone = JSON.parse(JSON.stringify(obj));
	arr.push(clone);
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.