Created
February 13, 2023 21:20
-
-
Save gnysek/d207ae7cae3724055396894f989b9f1e to your computer and use it in GitHub Desktop.
Singleton test
This file contains hidden or 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
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