Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
How do you measure performance / fps — Gideros Forum

How do you measure performance / fps

Tom2012Tom2012 Guru
edited September 2012 in General questions
Searched the forum but couldn't find the answer to this one.

Thanks

Tom

Likes: paulocarrasco

+1 -1 (+1 / -0 )Share on Facebook

Comments

  • Here's the code I usually use
     
    -- -------------------------------------------------------------
    -- local methods required to put an FPS counter on the screen...
     
    local frame = 0
    local timer = os.timer()
    local qFloor = math.floor
    local fps
     
    -- Global table for OSD
    DEBUG = { "","","","","","","","","","","","", }		
    local DEBUG_TXT = {}
     
    function DEBUG_RESET() for i=1,#DEBUG do DEBUG[i] = "" end end
     
    -- -------------------------------------------------------------
     
    local function updateFPS(e)
     
    	frame = frame + 1
    	if frame == 60 then
     
    		local currentTimer = os.timer()
    		fps:setText(""..qFloor(60 / (currentTimer - timer)))
     
    		local width = fps:getWidth()
    		fps:setPosition(320-(width+10), 28)
    		frame = 0; timer = currentTimer	
    	end
     
    	for i=1,#DEBUG_TXT do
    		DEBUG_TXT[i]:setText(DEBUG[i])
    	end
     
    end
     
    -- ------------------------------------------------
     
    initFPS = function(group)
     
    	fps = TextField.new(nil,"  ")
    	fps:setTextColor(0x00FFFF)
    	fps:setScale(2,2)
    	fps:addEventListener(Event.ENTER_FRAME,updateFPS)
    	group:addChild(fps)
     
    	local y = 20
    	for i=1,#DEBUG do
    		local d = TextField.new(nil,DEBUG[i])
    		d:setTextColor(0x00FFFF)
    		d:setScale(2,2)
    		d:setPosition(4,y); y = y + 18
    		group:addChild(d)
    		DEBUG_TXT[i] = d
    	end
     
    end
     
    initFPS(stage)	-- Add a quick FPS counter on the screen (REMOVE for final build)
    Just add the above to the end of main.lua file and you should be good to go.
    Also I added an extra bit - I declare a simple global table called DEBUG all with empty strings.

    What this means is that you can then set any element of the DEBUG array to any value (or string) and it'll be displayed on the screen.

    ie.

    DEBUG[1] = count
    DEBUG[2] = someString

    etc

    Any changes will get instantly updated on screen - it's useful to be able to put a "watch" on a particular value without having loads of print statements cluttering up the output log.

    You can call the DEBUG_RESET() function to clear all of the entries.

    Hope this helps.

    Jon...
    WhiteTree Games - Home, home on the web, where the bits and bytes they do play!
    #MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
  • bowerandybowerandy Guru
    edited September 2012
    @Tom2012, I use my BhDebugInfo class to display a simple debugging HUD that includes device info, fps and used memory. You can get it on GitHub. You just need to include the Lua file (and its font) in your project for it to work. You can turn if off by choosing "Exclude from execution" in the Gideros IDE.

    best regards
  • Thanks for the replies everyone.

    I found the best solution for me was:

    local frame = 0
    local timer = os.timer()
    local function displayFps()
    frame = frame + 1
    if frame == 60 then
    local currentTimer = os.timer()
    print(60 / (currentTimer - timer))
    frame = 0
    timer = currentTimer
    end
    end

    stage:addEventListener(Event.ENTER_FRAME, displayFps)
Sign In or Register to comment.