Scope versus Arg

Benchmark created on


Setup

var results = [];

function argCounter(...args) {
	return args.reduce((acc, n) => {
		return acc + n;
	}, 0);
}

function getObjectByIdParam(...args) {
	return { method: argCounter, args }
}

function reduceParam(obj) {
	return obj.method(...obj.args);
}

function getObjectByIdScope(...args) {
	return () => argCounter(...args);
}

function reduceScope(obj) {
	return obj();
}

Teardown

var results = [];

Test runner

Ready to run.

Testing in
TestOps/sec
Method
results.push(
	reduceParam(
		getObjectByIdParam(
			Math.random(),
			Math.random()
		)
	)
)
ready
Scope
results.push(
	reduceScope(
		getObjectByIdScope(
			Math.random(),
			Math.random()
		)
	)
)
ready

Revisions

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