Page 1 of 1

Pathfinding speed test

Posted: Thu Jan 03, 2013 4:58 am
by Vadi
Here's an alias I wrote to see the speed of pathfinding - it goes through all rooms in your map and tries to make a path to any other random room. In the end, it averages out the time it took for each result and gives you a number. It's ridiculously small, so pathfinding is appropriately ridiculously quick. Note that the stopwatch used has milisecond precision.

Re: Pathfinding speed test

Posted: Sat Sep 21, 2013 7:01 am
by Vadi
Updated version, thanks to ace:
Code: [show] | [select all] lua
watch = watch or createStopWatch()

local rooms = getRooms()

-- create a list of rooms that have at least one normal exit
local room_list = {}
for k, v in pairs(rooms) do
  if next(getRoomExits(k)) then
    table.insert(room_list, k)
  end
end

-- create a map with every room paired up with another random room
rooms = {}
for k, v in ipairs(room_list) do
  rooms[v] = math.random(#room_list)
end

-- pathfind from every room A to a random room B
local getPath = getPath
startStopWatch(watch)
for from, to in pairs(rooms) do
  getPath(from, to)
end
local t = stopStopWatch(watch)

display("Average time to pathfind from one room to a random other: "..t/#room_list.." seconds, tested with "..#room_list.." rooms.")