Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Should I replace math.random with a pregenerated table?
Started by MikeHart Apr 06 2010 04:22 PM

- - - - -
3 replies to this topic
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

MikeHart

[GLOBAL: userInfoPane.html]
MikeHart
  • Corona Geek

  • 1,278 posts
  • Corona SDK

Hi folks,

when I create a particle effect in my script, I use around 30 math.random calls during a frame.
This brings down the framerate (deltatime=99 .. 10 FPS). My idea is now to pregenerate a table with random values and read values from there. Did someone tried this already and can confirm a performance boost could it have no effect.

Cheers
Michael
uid: 5712 topic_id: 746 reply_id: 300746


[TOPIC: post.html]
#2

Eric

[GLOBAL: userInfoPane.html]
Eric
  • Contributor

  • 485 posts
  • Guests

If it's really that slow, we need to look into that.
uid: 54 topic_id: 746 reply_id: 1501


[TOPIC: post.html]
#3

MikeHart

[GLOBAL: userInfoPane.html]
MikeHart
  • Corona Geek

  • 1,278 posts
  • Corona SDK

Well, I just look into it again. I don't call just 30 times, it is 120 times I just noticed!!!

30 particles with 4 calls for x and y target position, the time for the transition and one for the scale of the particle. I think I go with a precalculated table and see how that works.
uid: 5712 topic_id: 746 reply_id: 1505


[TOPIC: post.html]
#4

Eric

[GLOBAL: userInfoPane.html]
Eric
  • Contributor

  • 485 posts
  • Guests

Ok. Lookups are always faster and if you have a large enough pre-calculated table, it won't be noticeable.
uid: 54 topic_id: 746 reply_id: 1506



[topic_controls]
[/topic_controls]