Bound method performance penalty

Benchmark created on


Description

Evaluate penalty introduced by passing bound method, as opposed to ordinary function

Setup

function test_func(iterable) {
	const arr = Array.from(iterable)
	return arr.reduce((acc, cur, idx, ar) => acc + cur, 0)
}

class Tst {
	test_func(iterable) {
		const arr = Array.from(iterable)
		return arr.reduce((acc, cur, idx, ar) => acc + cur, 0)
	}
}

function caller(func, ...args) {
	return func(...args)
}

const inst = new Tst()


const arr = new Array()
for (let i = 0; i < 1000; i++) arr[i] = i ** 2

Test runner

Ready to run.

Testing in
TestOps/sec
Simple function
caller(test_func, arr)
ready
Bound method
caller(inst.test_func.bind(inst), arr)
ready
Unbound method
caller(inst.test_func, arr)
ready

Revisions

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