2012-08-02 10:52:21 +00:00
|
|
|
#!/usr/bin/env luajit
|
|
|
|
|
|
|
|
local os = require("os")
|
|
|
|
|
2013-06-28 14:07:41 +00:00
|
|
|
local xmath = require("xmath")
|
2012-08-02 10:52:21 +00:00
|
|
|
|
|
|
|
|
2013-09-05 17:37:44 +00:00
|
|
|
-- XXX: perf regression? (See below PERF_REGRESSION)
|
|
|
|
local N = os.exit and (arg[1] and tostring(arg[1])) or 1e5 --1e6
|
2012-08-02 10:52:21 +00:00
|
|
|
|
|
|
|
local A,B = {}, {}
|
|
|
|
local V,W = {}, {}
|
|
|
|
|
2012-08-02 10:52:28 +00:00
|
|
|
local randvec
|
|
|
|
|
2013-06-22 11:31:09 +00:00
|
|
|
local args = { ... }
|
|
|
|
local ourname = args[1]
|
|
|
|
|
2012-08-02 10:52:28 +00:00
|
|
|
if (os.exit) then
|
|
|
|
local math = require("math")
|
|
|
|
|
|
|
|
randvec = function()
|
2013-06-28 14:07:41 +00:00
|
|
|
return xmath.vec2(math.random(), math.random())
|
2012-08-02 10:52:28 +00:00
|
|
|
end
|
2013-06-22 11:31:09 +00:00
|
|
|
|
|
|
|
print("Running stand-alone. ourname: "..tostring(ourname))
|
2012-08-02 10:52:28 +00:00
|
|
|
else
|
|
|
|
local randgen = require("randgen")
|
|
|
|
local s = randgen.new(true)
|
|
|
|
|
|
|
|
-- NOTE: factoring out the inner s:getdbl() into a separate function
|
|
|
|
-- reduces performance seriously (about an order of magnitude!)
|
|
|
|
randvec = function()
|
2013-06-28 14:07:41 +00:00
|
|
|
return xmath.vec2(s:getdbl(), s:getdbl())
|
2012-08-02 10:52:28 +00:00
|
|
|
end
|
2013-06-22 11:31:09 +00:00
|
|
|
|
|
|
|
-- Test optional arguments from our_require().
|
2013-08-18 19:24:25 +00:00
|
|
|
printf("Running %s embedded with opt arg %s", ourname, tostring(args[2]))
|
2012-08-02 10:52:21 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local t1 = os.clock()
|
|
|
|
|
2012-08-02 10:52:28 +00:00
|
|
|
if (os.exit == nil) then
|
|
|
|
local randgen = require("randgen")
|
|
|
|
local r = randgen.new(true)
|
|
|
|
|
|
|
|
for i=1,4*2*N do
|
|
|
|
-- This is to test the performance compared to a direct
|
|
|
|
-- ffiC.rand_jkiss_dbl() call in randgen.lua
|
|
|
|
r:getdbl()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local t2 = os.clock()
|
|
|
|
|
2012-08-02 10:52:21 +00:00
|
|
|
-- init random points and vectors
|
|
|
|
for i=1,N do
|
|
|
|
A[i] = randvec()
|
|
|
|
B[i] = randvec()
|
|
|
|
V[i] = randvec()
|
|
|
|
W[i] = randvec()
|
|
|
|
end
|
|
|
|
|
2012-08-02 10:52:28 +00:00
|
|
|
local t3 = os.clock()
|
2012-08-02 10:52:21 +00:00
|
|
|
|
2013-06-28 14:07:41 +00:00
|
|
|
local v = xmath.vec2(0, 0)
|
2012-08-02 10:52:21 +00:00
|
|
|
for i=1,N do
|
2013-06-28 14:07:41 +00:00
|
|
|
local intersp = xmath.intersect(A[i],V[i], B[i],W[i], true)
|
2012-08-19 12:52:18 +00:00
|
|
|
if (intersp ~= nil) then
|
|
|
|
v = v + intersp
|
|
|
|
end
|
2012-08-02 10:52:21 +00:00
|
|
|
end
|
|
|
|
|
2012-08-02 10:52:28 +00:00
|
|
|
local t4 = os.clock()
|
2012-08-02 10:52:21 +00:00
|
|
|
|
2012-08-02 10:52:28 +00:00
|
|
|
-- x86_64 (embedded): approx. 200 ms (vs. the 100 ms of direct
|
|
|
|
-- ffiC.rand_jkiss_dbl()):
|
2012-08-06 20:00:23 +00:00
|
|
|
-- x86: 170 ms
|
2013-05-17 10:41:57 +00:00
|
|
|
print("getdbl: ".. 1000*(t2-t1))
|
|
|
|
print("genpoints: ".. 1000*(t3-t2)) -- x86_64: 500 ms, x86: 700 ms
|
|
|
|
print("intersect: ".. 1000*(t4-t3)) -- x86_64, x86: about 35 ms <- thanks to allocation sinking (else, about 500 ms?)
|
|
|
|
print("result: ".. tostring(v))
|
2013-09-05 17:37:44 +00:00
|
|
|
|
|
|
|
-- PERF_REGRESSION: with N==1e6 getdbl, genpoints now about 1000ms from EDuke32!
|