Skip to content

Instantly share code, notes, and snippets.

@gnysek
Created February 13, 2023 21:20
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/d207ae7cae3724055396894f989b9f1e to your computer and use it in GitHub Desktop.
Save gnysek/d207ae7cae3724055396894f989b9f1e to your computer and use it in GitHub Desktop.
Singleton test
function Test() constructor {
static test = "--- singleton test";
}
Test();
function get_test() {
return static_get(Test);
}
/// timer
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 10000
///
global.singleton = new Test();
var a, s, t;
t = new timer("A");
repeat(repeats) {
a = Test.test;
}
t.total();
t = new timer("B");
repeat(repeats) {
a = static_get(Test).test;
}
t.total();
t = new timer("C");
repeat(repeats) {
a = get_test().test;
}
t.total();
t = new timer("D");
repeat(repeats) {
a = global.singleton.test;
}
t.total();
t = new timer("E");
s = static_get(Test);
repeat(repeats) {
a = s.test;
}
t.total();
t = new timer("F");
s = global.singleton;
repeat(repeats) {
a = s.test;
}
t.total();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment