Skip to content

Instantly share code, notes, and snippets.

@gnysek
Last active October 25, 2022 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gnysek/67ead1b19d7576c1c62ee5bbb8cd5517 to your computer and use it in GitHub Desktop.
Save gnysek/67ead1b19d7576c1c62ee5bbb8cd5517 to your computer and use it in GitHub Desktop.
tests of new GM 2022.11 functions
function timer(_name = "") constructor {
name = string(_name);
time = get_timer();
static total = function() {
var ddelta = get_timer() - time;
var ss = string_format( ddelta/repeats, 1, 10);
show_debug_message(string((ddelta)/1000) + "ms - " + ss + " per iteration " + name);
}
}
#macro repeats 500
global.test_array = array_create_ext(1000, function(){return irandom(10000);});
function array_foreach_func(val, key){
global.test_array[key] = irandom(10000);
};
function array_map_ext_func(val, key){
return irandom(10000);
}
function test() {
var i, t;
show_debug_message("... testing");
t = new timer("repeat");
repeat(repeats) {
i = 0;
repeat(1000) {
global.test_array[i] = irandom(10000);
i++;
}
}
t.total();
t = new timer("for");
repeat(repeats) {
for(i = 0; i < 1000; i++) {
global.test_array[i] = irandom(10000);
}
}
t.total();
t = new timer("array_foreach");
repeat(repeats) {
array_foreach(global.test_array, function(val, key){
global.test_array[key] = irandom(10000);
});
}
t.total();
t = new timer("array_foreach + array_foreach_func()");
repeat(repeats) {
array_foreach(global.test_array, array_foreach_func);
}
t.total();
t = new timer("array_map_ext");
repeat(repeats) {
array_map_ext(global.test_array, function(val, key){
return val+1;
});
}
t.total();
t = new timer("array_map_ext + array_map_ext_func");
repeat(repeats) {
array_map_ext(global.test_array, array_map_ext_func);
}
t.total();
t = new timer("array_map_ext + method:array_map_ext_func");
repeat(repeats) {
array_map_ext(global.test_array, method({}, array_map_ext_func));
}
t.total();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment