Last active
December 11, 2015 12:59
-
-
Save Jeija/4604759 to your computer and use it in GitHub Desktop.
Tool to compare speed between minetest.env:set_node() minetest.env:set_nodes() and set_nodes() with minp and maxp specified
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
time_setnodes = 0 | |
time_setnoare = 0 | |
time_setnode = 0 | |
amount_setnodes = 0 | |
amount_setnoare = 0 | |
amount_setnode = 0 | |
function benchmark_setnodes(minp, maxp) | |
local t1 = os.time() | |
local nodes = {} | |
for x=minp.x,maxp.x do | |
for y=minp.y,maxp.y do | |
for z=minp.z,maxp.z do | |
table.insert(nodes, {pos = {x = x, y = y, z = z}, node = {name = "default:stone"}}) | |
end | |
end | |
end | |
minetest.env:set_nodes(nodes) | |
local t2 = os.time() | |
return t2-t1 | |
end | |
function benchmark_setnode(minp, maxp) | |
local t2 = os.time() | |
for x=minp.x,maxp.x do | |
for y=minp.y,maxp.y do | |
for z=minp.z,maxp.z do | |
minetest.env:set_node({x=x, y=y, z=z}, {name="default:wood"}) | |
end | |
end | |
end | |
local t3 = os.time() | |
return t3-t2 | |
end | |
function benchmark_setnodes_area(minp, maxp) | |
local t2 = os.time() | |
minetest.env:set_nodes({{minp = minp, maxp = maxp, node={name="default:dirt"}}}) | |
local t3 = os.time() | |
return t3-t2 | |
end | |
minetest.register_craftitem("test:test", { | |
description = "Testcraftitem", | |
inventory_image = "default_lava.png", | |
on_use = function(itemstack, dropper, pointed_thing) | |
if pointed_thing.type ~= "node" then | |
return | |
end | |
local pos = pointed_thing.under | |
local minp = {x=pos.x-50, y=pos.y+2, z=pos.z-50} | |
local maxp = {x=pos.x+50, y=pos.y+12, z=pos.z+50} | |
local mode = math.random(1, 3) | |
local tocall = {} | |
thistime_setnoare = 0 | |
thistime_setnode = 0 | |
thistime_setnodes = 0 | |
if mode == 1 then | |
amount_setnoare = amount_setnoare + 1 | |
thistime_setnoare = benchmark_setnodes_area(minp, maxp) | |
time_setnoare = time_setnoare * ((amount_setnoare-1)/amount_setnoare) | |
+ thistime_setnoare * (1/amount_setnoare) | |
elseif mode == 2 then | |
amount_setnodes = amount_setnodes + 1 | |
thistime_setnodes = benchmark_setnodes(minp, maxp) | |
time_setnodes = time_setnodes * ((amount_setnodes-1)/amount_setnodes) | |
+ thistime_setnodes * (1/amount_setnodes) | |
elseif mode == 3 then | |
amount_setnode = amount_setnode + 1 | |
thistime_setnode = benchmark_setnode(minp, maxp) | |
time_setnode = time_setnode * ((amount_setnode-1)/amount_setnode) | |
+ thistime_setnode * (1/amount_setnode) | |
end | |
print("This time: set_nodes(): "..thistime_setnodes.."; set_node(): "..thistime_setnode.." set_nodes() with area: "..thistime_setnoare) | |
print("Average: set_nodes(): "..time_setnodes.."; set_node(): "..time_setnode.." set_nodes() with area: "..time_setnoare) | |
end, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment