maxIterations@10000
local randomSeed,random=Core.randomSeed,Core.random
randomSeed(1,1)
function testDistance1()
local distanceNum=0; randomSeed(1,1)
for i=1,maxIterations do
local x1,x2,y1,y2=random(0,320),random(0,320),random(0,480),random(0,480)
local dx, dy = math.abs(x1 - x2), math.abs(y1 - y2)
distanceNum = math.sqrt(dx*dx + dy*dy)
end
end
function testDistance2()
local distanceNum=0; randomSeed(1,1)
for i=1,maxIterations do
local x1,x2,y1,y2=random(0,320),random(0,320),random(0,480),random(0,480)
distanceNum = math.sqrt((x1 - x2)^2 + (y1 - y2)^2)
end
end
function testDistance3()
local distanceNum=0; randomSeed(1,1)
for i=1,maxIterations do
local x1,x2,y1,y2=random(0,320),random(0,320),random(0,480),random(0,480)
local xfactor = x2-x1 ; local yfactor = y2-y1
distanceNum = math.sqrt((xfactor*xfactor) + (yfactor*yfactor))
end
end
--4th function doesn't work:
MATHSQRT @ (|
local enteredNum=...
return math.sqrt(enteredNum[1])
|)
function testDistance4()
local distanceNum=0; randomSeed(1,1)
for i=1,maxIterations do
local x1,x2,y1,y2=random(0,320),random(0,320),random(0,480),random(0,480)
local xfactor = x2-x1 ; local yfactor = y2-y1
distanceNum = MATHSQRT((xfactor*xfactor) + (yfactor*yfactor))
end
end
--Let's test first 3 functions:
Core.profilerReset()
Core.profilerStart()
for loop=1,10 do
testDistance1()
testDistance2()
testDistance3()
--testDistance4()
end
Core.profilerStop()
-- print the results of the profiler
result=Core.profilerReport()
print("Number of tests:",maxIterations*10)
for k,v in pairs(result) do
local found=false
for k2,v2 in pairs(v) do
if found and k2=="time" then print(v1,v2) end
if k2=="name" and string.sub(v2,1,4)=="test" then v1=v2 found=true end
end
end
Comments
2: I'm not sure what you mean - a macro won't make it any faster - it basically replaces the text with the text in the macro as it gets converted to bytecode. The bytecode is then executed.
In some cases the macro will be faster than using a variable - but only slightly. eg:
variable:
Likes: Apollo14
https://deluxepixel.com
Likes: Apollo14
https://deluxepixel.com
Likes: Apollo14
https://deluxepixel.com
"What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
“The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
https://deluxepixel.com
Number of tests: 10000000
test1 24.56468319438
test2 22.882652866686
test 2 being the mutation operators. Maybe something happened on the computer that slowed it down in your case for the 2nd test?
https://deluxepixel.com
I was testing these functions in a temporary draft project with lots of dirty code commented out. Mutation operators are always slower there, something is slowing them down.
Does commented out code affect perfomance?
But when I created blank V2 project without commented out stuff, mutation operators work faster as we normally expect.
I've attached 2 projects here:
"What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
“The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
https://deluxepixel.com
Likes: Apollo14
https://deluxepixel.com