Adding properties vs an object literal with all the properties

Benchmark created on


Setup

var code = [];
for (var i = 0; i < 10000; i++) {
	code.push(`o[${Math.random()}] = ${Math.random()};`);
}
var add_properties = new Function("var o = {}; "+code.join(" ") + " return o; ");

var object_literal = new Function("return " + JSON.stringify(full));

var full = add_properties();

var assigned_properties = new Function("var o = {}; Object.assign(o, " + JSON.stringify(full) + "); return o;");

var spread_properties = function() { var o = { ...full }; return o; };


Test runner

Ready to run.

Testing in
TestOps/sec
Adding Properties
add_properties();
ready
Declared Object Literal
object_literal();
ready
Object.assign Properties into Object
assigned_properties();
ready
{ ...other_obj }
spread_properties();
ready

Revisions

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