Object creation (v4)

Revision 4 of this benchmark created on


Setup

function createObj(name, value) {
	return { name, value }
}

class Foo1 {}

class Foo2 {
	constructor(name, value) {
		this.name = name
		this.value = name
	}
}

class Foo3 {
	constructor() {
		this.foo = () => {}
		this.bar = () => {}
	}
}

class Foo4 {
	foo() {}
	bar() {}
}

function FunctionClass() {}

Test runner

Ready to run.

Testing in
TestOps/sec
new Object
{}
ready
class Instance
new Foo1()
ready
create instance with defaults
new Foo2("Foobar", 12)
ready
create object via function
createObj("MyObject", 135)
ready
create object via new operator
new Object()
ready
create instance via Function
new FunctionClass()
ready
create instance assign functions in constructor
new Foo3()
ready
create instance with methods
new Foo4()
ready
create array with objects 1
[
	createObj("MyObject", 135),
	createObj("MyObject", 135),
	createObj("MyObject", 135),
	createObj("MyObject", 135),
	createObj("MyObject", 135),
	createObj("MyObject", 135),
	createObj("MyObject", 135),
	createObj("MyObject", 135),
	createObj("MyObject", 135),
	createObj("MyObject", 135)
]
ready
create array of instances 1
[
	new Foo2("MyInstance", 122),
	new Foo2("MyInstance", 122),
	new Foo2("MyInstance", 122),
	new Foo2("MyInstance", 122),
	new Foo2("MyInstance", 122),
	new Foo2("MyInstance", 122),
	new Foo2("MyInstance", 122),
	new Foo2("MyInstance", 122),
	new Foo2("MyInstance", 122),
	new Foo2("MyInstance", 122)
]
ready
create array of instances 2
[
	new Foo1(),
	new Foo1(),
	new Foo1(),
	new Foo1(),
	new Foo1(),
	new Foo1(),
	new Foo1(),
	new Foo1(),
	new Foo1(),
	new Foo1()
]
ready
create array with objects 2
[
	{ foo: () => {}, name: 'bar' },
	{ foo: () => {}, name: 'bar' },
	{ foo: () => {}, name: 'bar' },
	{ foo: () => {}, name: 'bar' },
	{ foo: () => {}, name: 'bar' },
	{ foo: () => {}, name: 'bar' },
	{ foo: () => {}, name: 'bar' },
	{ foo: () => {}, name: 'bar' },
	{ foo: () => {}, name: 'bar' },
	{ foo: () => {}, name: 'bar' }
]
ready
create array with objects 3
[
	{ foo() {}, name: 'bar' },
	{ foo() {}, name: 'bar' },
	{ foo() {}, name: 'bar' },
	{ foo() {}, name: 'bar' },
	{ foo() {}, name: 'bar' },
	{ foo() {}, name: 'bar' },
	{ foo() {}, name: 'bar' },
	{ foo() {}, name: 'bar' },
	{ foo() {}, name: 'bar' },
	{ foo() {}, name: 'bar' }
]
ready

Revisions

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