Adding properties to an object (v2)

Revision 2 of this 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; };

var object_literal_inside_with_statement = new Function("with({}) { return " + JSON.stringify(full) + " }");

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
Literal inside with() statement
object_literal_inside_with_statement();
ready

Revisions

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