Here are the results from the Swedish test....![]()
Following part of the code has been examined and measured. It will show the difference between of using CONSTRUCTION and SIM_BUILDING table to find CARGO at stock in a selected industry. In this example I have only placed one unique industry among many vanilla industries on my test map. I have removed the logic after the industry has been found, so this is showing the time it takes just to find the industry on a small map in the beginning of a new game. It will be worse as longer the game is running, as more buildings will increase the CONSTRUCTION table.
In this experiment I got 69 items in the SIM_BUILDING table and 1584 items in the CONSTRUCTION table
timer.start()
local Constructions = game.interface.getEntities({ pos = {0,0}, radius = math.huge }, { type = "CONSTRUCTION" })
local Contime = timer.stop()
timer.start()
local SimBuild = game.interface.getEntities({ pos = {0,0}, radius = math.huge }, { type = "SIM_BUILDING" })
local Simtime = timer.stop()
-- for loop to find the industry, by searching in SIM_BUILDING table
timer.start()
for i=1, #SimBuild do
local ConId = game.interface.getEntity(SimBuild[i]).stockList
local fileName = game.interface.getEntity(ConId).fileName
if string.match(fileName, "track_warehouse.con") then
end
end
local LoopSIM_BUILDINGtime = timer.stop()
-- for loop to find the industry, by searching in only CONSTRUCTION table
timer.start()
for i=1, #Constructions do
local fileName = game.interface.getEntity(Constructions[i]).fileName
if string.match(fileName, "track_warehouse.con") then
end
end
local LoopCONSTRUCTIONtime = timer.stop()
--]]
print("getEntities 'CONSTRUCTION' time =",Contime*1000," getEntities 'SIM_BUILDING' time =",Simtime*1000," For Loop 'SIM_BUILDING' time =",LoopSIM_BUILDINGtime*1000," For Loop 'CONSTRUCTION' time =",LoopCONSTRUCTIONtime*1000)
print ("#SIM_BUILING =",#SimBuild, " #CONSTRUCTION =",#Constructions)
Alles anzeigen
| code | used time (ms) |
| game.interface.getEntities "CONSTRUCTION" | 3 to 4 |
| game.interface.getEntities "SIM_BUILDING" | 1 to 3 |
| for loop using SIM_BUILDING | 3 to 4 |
| for loop using CONSTRUCTION | 48 to 54 |
The results I got confirms what I saw earlier as each game script loop is repeated about every 200ms. Using CONSTRUCTION table has a big impact on the performance as it takes about 25% to execute. The time will also vary depending on the computer system. This was tested on a computer based on, Intel(R) Core(TM) i9-9900KF CPU @ 3.60GHz, 32.0 GB, Geforce RTX 2080, CPU is running @ 4800 MHz and GPU @ 1965 MHz.