Howdy, Stranger!

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

Optimizing your code!

edited November 2015 in Wiki Posts: 116

Hey guys,
I have been playing with Codea for a couple of years now, but i was always writing crappy uneffective code :D
So i am starting this discussion for you to post your tips and trics to write more quick code.
What i learned until now:
•local variables are faster than global ones

x*0.5 is lot faster than x/2

x*x is faster than x^2 or math.pow(x,2)

x * (1/3) is faster than x/3

•if you use a function a lot of times (example: in a for loop), save the function in a local variable like sin = math.sin and using it like this sin(x) instead of calling math.sin(x) repeatedly.

• meshes are a lot faster than lot of rects

So this is all i know. Feel free to improve my thoughts!

EDIT 1: after seeing the pdf posted by yojimba, where everything is explained nicely, i am wondering if there are some codea-only optimization possibilities?

Comments

  • Posts: 116

    Can somebody please fix these code blocks? Wanted them to be not on a new line

  • Posts: 2,020

    code blocks go on new lines (that's what the "block" part means)

    use two back-quotes for in-line code like this

    use two back-quotes for `in-line code` like this
    

    this chapter from Lua gems is handy:

    www.lua.org/gems/sample.pdf

Sign In or Register to comment.