inline (v3)

Revision 3 of this benchmark created on


Setup

const _map = (arr, fn) => {
  const r = []
  for (let i = 0; i < arr.length; i++)r.push(fn(arr[i]))
  return r
}

const bindClone = (fn, key) => {
	let _fn = bindClone.dict.get(key);
	if (_fn === undefined) {
 		_fn = fn.bind({})
    	bindClone.dict.set(key, _fn)
 	}
 	return _fn
};
bindClone.dict = new WeakMap()
const stringClone = (fn, key) => {
	let _fn = stringClone.dict.get(key);
	if (_fn === undefined) {
    	_fn = new Function(`return (${fn.toString()})`)()
 		stringClone.dict.set(key, _fn)
 	}
 	return _fn
};
stringClone.dict = new WeakMap()

const bindCloneMap = (arr, fn) => bindClone(_map, fn)(arr, fn)
const stringCloneMap = (arr, fn) => stringClone(_map, fn)(arr, fn)

const each1 = (i) => i + 1
const each2 = (i) => i + 2
const arr = new Array(1000).fill(true)

Test runner

Ready to run.

Testing in
TestOps/sec
_map
var r = 0
for (let i = 0; i < 1000; i++){
	var a = _map(arr, each1).length;
	var b = _map(arr, each2).length;
	r = a + b
}
ready
bindCloneMap
var r = 0
for (let i = 0; i < 1000; i++){
	var a = bindCloneMap(arr, each1).length;
	var b = bindCloneMap(arr, each2).length;
	r = a + b
}
ready
stringCloneMap
var r = 0
for (let i = 0; i < 1000; i++){
	var a = stringCloneMap(arr, each1).length;
	var b = stringCloneMap(arr, each2).length;
	r = a + b
}
ready

Revisions

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