-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.lua
40 lines (33 loc) · 984 Bytes
/
test.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
local delaunay = require ('delaunay')
local Point = delaunay.Point
math.randomseed(os.time())
local function newPoint()
local x, y = math.random(), math.random()
return Point(x * 1000, y * 1000)
end
local MAX_POINTS = arg[1] or 500
local N_TESTS = arg[2] or 10
local function genPoints(n)
local points = {}
for i = 1, n do
points[i] = newPoint()
end
return points
end
local function time(f, p)
collectgarbage()
local start_time = os.clock()
local start_mem = collectgarbage('count')
local result = f((p))
local duration = (os.clock() - start_time) * 1000
assert(result~=nil, 'Unexpected output, returned nil')
return duration, (collectgarbage('count') - start_mem)
end
local function main()
for i = 1, N_TESTS do
local p = genPoints(MAX_POINTS)
local duration, mem = time(delaunay.triangulate, p)
print(('Test %02d: triangulating %04d points in %.2f ms, memory usage: %f Kb'):format(i, MAX_POINTS, duration, mem))
end
end
main()