Created
May 21, 2016 09:48
-
-
Save HybridDog/ea50aebbc6befec4faeff5f58c65913c to your computer and use it in GitHub Desktop.
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
local TIME = 0.5 | |
local clock = minetest.get_us_time | |
local us = TIME * 1000000 | |
local function benchmark_function(fct, ...) | |
local start = clock() | |
local fin = start | |
local total = 0 | |
while fin - start < us do | |
fct(...) | |
total = total + 1 | |
fin = clock() | |
end | |
return total / TIME | |
end | |
local table_insert | |
local function do_test() | |
local t = {} | |
local t0 = benchmark_function(function() | |
t[#t+1] = "TEST" | |
end) | |
t = {} | |
local t1 = benchmark_function(function() | |
table_insert(t, "TEST") | |
end) | |
t = {} | |
local t3 = benchmark_function(function() | |
table_insert(t, 1, "TEST") | |
end) | |
t = {} | |
local t4 = benchmark_function(function() | |
table_insert(t, -1, "TEST") | |
end) | |
return {t0, t1, t3, t4} | |
end | |
local function do_tests() | |
table_insert = table.insert | |
local wo = do_test() | |
local tinsert = table_insert | |
function table_insert(t, v, n) | |
if n then | |
return tinsert(t, v, n) | |
end | |
t[#t+1] = v | |
end | |
local w = do_test() | |
for i,v in ipairs(w) do | |
local n = wo[i] | |
print(n, v, v/n) | |
end | |
print("\n") | |
end | |
minetest.register_chatcommand("dot", { | |
func = do_tests | |
}) | |
--[[results | |
2815074 2722314 0.96704882358332 | |
mo 1993646 2637518 1.3229620504342 | |
mo 47916 46816 0.97704315886134 | |
mo 47778 48210 1.0090418184101 | |
mo 2785130 2808012 1.0082157744881 | |
mo 1989236 2677492 1.3459901188195 | |
mo 47382 48612 1.0259592250222 | |
mo 46522 48576 1.0441511542926 | |
mo 2832966 2811398 0.992386777674 | |
mo 1947756 2707548 1.3900858218381 | |
mo 46994 47722 1.0154913393199 | |
mo 48644 46884 0.9638187649042 | |
mo 2754498 2841218 1.0314830506321 | |
mo 1971566 2670578 1.3545465888537 | |
mo 45848 48506 1.0579741755366 | |
mo 48582 48546 0.99925898480919 | |
mo 2822548 2788368 0.98789037422924 | |
mo 1965276 2634954 1.3407551916372 | |
mo 47998 46750 0.97399891662153 | |
mo 47208 46710 0.98945094051856 | |
mo 2726202 2729794 1.0013175839501 | |
mo 1917620 2604736 1.3583170805478 | |
mo 46832 46786 0.99901776563034 | |
mo 46776 46724 0.99888831879596 | |
--]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment