ShiVa3D
Profiling how long functions take to run [SOLVED]
All about the StoneScriptProfiling how long functions take to run
by miyudreams » 05 Jul 2012, 03:35
Hi,
I'm trying to figure out which parts of my code run particularly slow. However, I'm not sure where to get the time. I can't use application.getLastFrameTime() or any of those frame time functions because they return the same values whether you place it at the end or at the beginning of the script.
I tried system.getTimeOfDay(). I put a big calculation and a for loop in my function to make sure it is an "expensive" function, so the time to execute that function should be more than a second. The before and after getTimeOfDay returns different values. But most functions seem to be < than a second, so before and after are the same.
Is this the best way to profile for "expensive" time consuming functions in the code?
Are there other API that are better suited for profiling time?
Thanks
I'm trying to figure out which parts of my code run particularly slow. However, I'm not sure where to get the time. I can't use application.getLastFrameTime() or any of those frame time functions because they return the same values whether you place it at the end or at the beginning of the script.
I tried system.getTimeOfDay(). I put a big calculation and a for loop in my function to make sure it is an "expensive" function, so the time to execute that function should be more than a second. The before and after getTimeOfDay returns different values. But most functions seem to be < than a second, so before and after are the same.
Is this the best way to profile for "expensive" time consuming functions in the code?
Are there other API that are better suited for profiling time?
Thanks
- miyudreams
- Senior Boarder

- Posts: 61
Re: Profiling how long functions take to run
by broozar » 05 Jul 2012, 06:21
what you try to do is easily accomplished using the Performance Reporter in ShiVa ADVANCED.
all profiling that can be done by script with any ShiVa edition is in the debug.* API. function time is not part of it though.
all profiling that can be done by script with any ShiVa edition is in the debug.* API. function time is not part of it though.
Re: Profiling how long functions take to run [SOLVED]
by freezer » 05 Jul 2012, 16:00
not got around to it... but...
i intend to just use an onEnterFrame function and a non local counter variable.
on pass 0 it will execute a function 1000 times in a loop,
when on pass 1 it will execute another function 1000 times in a loop...
e.g.
the one consideration is if the application is optimising itself to run at 60 fps or such like... not looked into that (but use 60fps in some movement calcs... so I believe it does)... then it may not be accurate???
i intend to just use an onEnterFrame function and a non local counter variable.
on pass 0 it will execute a function 1000 times in a loop,
when on pass 1 it will execute another function 1000 times in a loop...
e.g.
- Code: Select all
--------------------------------------------------------------------------------
function game.onEnterFrame ( )
--------------------------------------------------------------------------------
log.message ( "n = "..n.."t"..application.getLastFrameTime() )
local i
if(this.n()==0) then
for i = 0, 999 do
local hBall = application.getCurrentUserSceneTaggedObject("Ball")
end
elseif(this.n()==1) then
for i = 0, 999 do
local hObject = scene.createRuntimeObject(hScene, "ball")
end
end
this.n(this.n()+1)
if(this.n()>1) then
this.n(0)
end
--------------------------------------------------------------------------------
end
--------------------------------------------------------------------------------
the one consideration is if the application is optimising itself to run at 60 fps or such like... not looked into that (but use 60fps in some movement calcs... so I believe it does)... then it may not be accurate???
- freezer
- Gold Boarder

- Posts: 164
Re: Profiling how long functions take to run
by Fraser » 05 Jul 2012, 18:55
Your idea with onenterframe seems good.
you could use application.setMinFrameTime ( 0.001 ) to reduce the granularity.
I was profiling the speed of lua tables versus shiva tables and also string.getbyte.
I used a keypress to kick off a very long loop.
I used a hand stop watch while watching the log window.
An API function to get system tick or millis would be useful.
you could use application.setMinFrameTime ( 0.001 ) to reduce the granularity.
I was profiling the speed of lua tables versus shiva tables and also string.getbyte.
I used a keypress to kick off a very long loop.
I used a hand stop watch while watching the log window.
An API function to get system tick or millis would be useful.
Fraser,
http://www.silicondroid.com
http://www.silicondroid.com
Re: Profiling how long functions take to run
by miyudreams » 06 Jul 2012, 04:57
Thank you for the responses. Without the Advanced licence I don't have access to the Performance Reporter. The loop example suggested by freezer using onEnterFrame to measure an average for my functions of interest is the only feasible way.
If I run my game on my old "slow" Android device, then everything will run slow in seconds which is the API function available. It would be nice to have the milliseconds API exposed, but I suspect it's not because there's got to be a good reason for the Advanced licence. Now I know why, a very good reason.
If I run my game on my old "slow" Android device, then everything will run slow in seconds which is the API function available. It would be nice to have the milliseconds API exposed, but I suspect it's not because there's got to be a good reason for the Advanced licence. Now I know why, a very good reason.
- miyudreams
- Senior Boarder

- Posts: 61
5 posts
• Page 1 of 1
