Last active
February 16, 2025 10:09
-
-
Save tinkerer-red/ce82b8f78f33fefec1586cd8098e3fe5 to your computer and use it in GitHub Desktop.
`array_contains_other` Attempt to search array for non default values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
new Benchmark("array_contains_not", [ | |
new TestCase("manually checked for()", function(iterations) { | |
repeat (iterations) { | |
var result = func(testArray, default_value); | |
} | |
}, | |
function(){ | |
//initiallizer (is not accounted for in the benchmark test) | |
default_value = undefined; | |
testArray = array_create(100, default_value) | |
testArray[50] = true; | |
func = function(_array, _value, _offset=0, _length=array_length(_array)-_offset) { | |
var _end = _offset + _length | |
for (var i = _offset; i < _end; i++) { | |
if (_array[i] != _value) return true; | |
} | |
return false; | |
} | |
}), | |
new TestCase("manually checked repat()", function(iterations) { | |
repeat (iterations) { | |
var result = func(testArray, default_value); | |
} | |
}, | |
function(){ | |
//initiallizer (is not accounted for in the benchmark test) | |
default_value = undefined; | |
testArray = array_create(100, default_value) | |
testArray[50] = true; | |
func = function(_array, _value, _offset=0, _length=array_length(_array)-_offset) { | |
var i = _offset; | |
repeat(_length) { | |
if (_array[i] != _value) return true; | |
i++} | |
return false; | |
} | |
}), | |
new TestCase("array_contains_ext", function(iterations) { | |
repeat (iterations) { | |
var result = func(testArray, default_value); | |
} | |
}, | |
function(){ | |
//initiallizer (is not accounted for in the benchmark test) | |
default_value = undefined; | |
testArray = array_create(100, default_value) | |
testArray[50] = true; | |
func = function(_array, _value, _offset=0, _length=array_length(_array)-_offset) { | |
static __checker_arr = []; | |
static __region_arr = []; | |
__checker_arr[0] = _value; | |
array_copy(__region_arr, 0, _array, _offset, _length); | |
var _result = array_contains_ext(__checker_arr, _array, true); | |
array_resize(__checker_arr, 0); | |
array_resize(__region_arr, 0); | |
return _result; | |
} | |
}), | |
new TestCase("array_find_index", function(iterations) { | |
repeat (iterations) { | |
var result = func(testArray, default_value); | |
} | |
}, | |
function(){ | |
//initiallizer (is not accounted for in the benchmark test) | |
default_value = undefined; | |
testArray = array_create(100, default_value) | |
testArray[50] = true; | |
func = function(_array, _value, _offset=0, _length=array_length(_array)-_offset) { | |
static __args = {}; | |
__args._value = _value; | |
static _method = method(__args, function(_element, _index) { | |
return (_element != _value); | |
}) | |
return array_find_index(_array, _method, _offset, _length) | |
} | |
}), | |
new TestCase("array_all", function(iterations) { | |
repeat (iterations) { | |
var result = func(testArray, default_value); | |
} | |
}, | |
function(){ | |
//initiallizer (is not accounted for in the benchmark test) | |
default_value = undefined; | |
testArray = array_create(100, default_value) | |
testArray[50] = true; | |
func = function(_array, _value, _offset=0, _length=array_length(_array)-_offset) { | |
static __args = {}; | |
__args._value = _value; | |
static _method = method(__args, function(_element, _index) { | |
return (_element == _value); | |
}) | |
return array_all(_array, _method, _offset, _length) | |
} | |
}), | |
new TestCase("array_any", function(iterations) { | |
repeat (iterations) { | |
var result = func(testArray, default_value); | |
} | |
}, | |
function(){ | |
//initiallizer (is not accounted for in the benchmark test) | |
default_value = undefined; | |
testArray = array_create(100, default_value) | |
testArray[50] = true; | |
func = function(_array, _value, _offset=0, _length=array_length(_array)-_offset) { | |
static __args = {}; | |
__args._value = _value; | |
static _method = method(__args, function(_element, _index) { | |
return (_element != _value); | |
}) | |
return array_any(_array, _method, _offset, _length) | |
} | |
}), | |
new TestCase("array_find_index (is_struct)", function(iterations) { | |
repeat (iterations) { | |
var result = func(testArray, default_value); | |
} | |
}, | |
function(){ | |
//initiallizer (is not accounted for in the benchmark test) | |
default_value = undefined; | |
testArray = array_create(100, default_value) | |
testArray[50] = true; | |
func = function(_array, _value, _offset=0, _length=array_length(_array)-_offset) { | |
return array_find_index(_array, is_struct, _offset, _length) | |
} | |
}), | |
new TestCase("array_find_index (bool)", function(iterations) { | |
repeat (iterations) { | |
var result = func(testArray, default_value); | |
} | |
}, | |
function(){ | |
//initiallizer (is not accounted for in the benchmark test) | |
default_value = false; | |
testArray = array_create(100, default_value) | |
testArray[50] = true; | |
func = function(_array, _value, _offset=0, _length=array_length(_array)-_offset) { | |
return array_find_index(_array, bool, _offset, _length) | |
} | |
}), | |
]), |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment