aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWesley <wesley.werner@gmail.com>2018-10-27 09:40:29 +0200
committerWesley <wesley.werner@gmail.com>2018-10-27 09:40:29 +0200
commit0406b05840f88274fe374a1058aabceaa32ee6cf (patch)
tree9d94add4b218f45e65d87751033e217e19ca77a7
parentf329ba1d9663175ea0b4955f502b0ba761cdf2a6 (diff)
downloadlua-star-0406b05840f88274fe374a1058aabceaa32ee6cf.tar.xz
Add performance test
-rw-r--r--.gitignore1
-rw-r--r--README.md20
-rw-r--r--tests/performance.lua63
3 files changed, 83 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index a813bbb..59cfc88 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
example/lua-star.lua
+tests/lua-star.lua
diff --git a/README.md b/README.md
index 6fd2ebe..5cb49b5 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# lua-star
-[![Build Status](https://travis-ci.org/wesleywerner/lua-star.svg?branch=master)](https://travis-ci.org/wesleywerner/lua-star) Easy A* path finding for Lua
+[![Build Status](https://travis-ci.org/wesleywerner/lua-star.svg?branch=master)](https://travis-ci.org/wesleywerner/lua-star) Lua-star is a pure Lua A* path-finding library.
![lua star example screenshot](example/lua-star-01.png)
@@ -60,6 +60,24 @@ Unit testing is done with busted, the `.busted` config already defines everythin
busted
+# Performance
+
+There is a performance measurement tool in `tests/performance.lua`, it calculates the average time to find a path on a large, random map.
+
+ # copy the lib to tests
+ $ cp ../src/lua-star.lua .
+
+ # measure performance
+ $ lua performance.lua
+ Running with seed 1540584306
+ Building a map of 3000x3000...
+ Precalculating 6000 random start/goal positions...
+ Finding 1000 paths...
+ Done in 16.37 seconds.
+ That is 0.0164 seconds, or 16 milliseconds, per path.
+ The map has 9.0 million locations, with about 65% open space.
+
+
# Example
There is an [interactive example](example/main.lua) that can be run with [Love](https://love2d.org).
diff --git a/tests/performance.lua b/tests/performance.lua
new file mode 100644
index 0000000..dfdbafa
--- /dev/null
+++ b/tests/performance.lua
@@ -0,0 +1,63 @@
+--[[
+ Copyright 2018 Wesley Werner <wesley.werner@gmail.com>
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+]]--
+
+local luastar = require("lua-star")
+local map = { }
+local mapsize = 3000
+local numberOfTests = 1000
+local mapDensity = 0.65
+
+local seed = os.time()
+math.randomseed(seed)
+print (string.format("Running with seed %d", seed))
+
+print (string.format("Building a map of %dx%d...", mapsize, mapsize))
+for x=1, mapsize do
+ map[x] = {}
+ for y=1, mapsize do
+ map[x][y] = math.random()
+ end
+end
+
+-- precalculate a bunch of start and goal positions
+-- doubled up for each start/goal pair
+
+print (string.format("Precalculating %d random start/goal positions...", mapsize * 2))
+local testPoints = { }
+for i = 1, mapsize * 2 do
+ table.insert (testPoints, { x = math.random(1, mapsize), y = math.random(1, mapsize)})
+end
+
+print (string.format("Finding %d paths...", numberOfTests))
+function positionIsOpenFunc(x, y)
+ return map[x][y] > mapDensity
+end
+local testStart = os.clock()
+for testNumber = 1, numberOfTests do
+ luastar:find(
+ mapsize, mapsize, -- map size
+ table.remove (testPoints), -- start
+ table.remove (testPoints), -- goal
+ positionIsOpenFunc)
+end
+local testEnd = os.clock()
+local totalSec = testEnd - testStart
+local pathSec = totalSec / numberOfTests
+
+print (string.format([[
+ Done in %.2f seconds.
+ That is %.4f seconds, or %d milliseconds, per path.
+ The map has %.1f million locations, with about %d%% open space.]],
+ totalSec, -- total seconds
+ pathSec, -- seconds per path
+ pathSec*1000, -- milliseconds per path
+ (mapsize*mapsize)/1000000, -- number of locations
+ mapDensity*100 -- % open space on the map
+))