It looks like you're new here. If you want to get involved, click one of these buttons!

- 7.3K All Categories
- 8 Help with translations
- 4K General questions
- 98 Roadmap
- 324 Game & application design
- 292 Plugins
- 65 User experience
- 69 Marketplace
- 274 Code snippets
- 33 Building a team?
- 246 Suggestions & requests
- 344 Announce your apps made with Gideros.
- 87 Step by step tutorials
- 606 Bugs and issues
- 176 Introduce yourself
- 189 Announcements
- 79 Forum talk
- 384 Relax cafe

Apollo14
Member

Hi guys!

I've checked 3 methods of getting distance between two points.

I have 2 questions:

1) Why does Profiler print results when 'maxIterations' is set to 10.000, but doesn't print anything when 'maxIterations=1.000.000'?

2) How to improve 3rd function? Can we put math.sqrt in Macro function? I don't get how to make it work:

(p. s. I don't know, maybe 'bump' can measure distance better, but I don't feel I really need it in my current projects, and I'm trying to understand how macro functions work.

Thanks!

Test project's code:

I've checked 3 methods of getting distance between two points.

Number of tests: 1000000 testDistance1 2.1159432063358 testDistance2 1.6703890134563 testDistance3 1.6123716717074 |

1) Why does Profiler print results when 'maxIterations' is set to 10.000, but doesn't print anything when 'maxIterations=1.000.000'?

2) How to improve 3rd function? Can we put math.sqrt in Macro function? I don't get how to make it work:

MATHSQRT @ (| local enteredNum=... return math.sqrt(enteredNum[1]) |) |

Thanks!

Test project's code:

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 |

> Newcomers roadmap: from where to start learning Gideros

*"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)

“The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)

## 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