测量Corona SDK中图像加载的经过时间 [英] measure elapsed time of image loading in Corona SDK

查看:188
本文介绍了测量Corona SDK中图像加载的经过时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Corona SDK中对大图像的加载进行基准测试。

I'm trying to benchmark the loading of large images in Corona SDK.

local startTime = system.getTimer()
local myImage = display.newImageRect( "someImage.jpg", 1024, 768 )
local endTime = system.getTimer()
print( endTime - startTime ) -- prints 8.4319999999998

这将返回大约8毫秒的值。我知道加载一个显示图像需要更长的时间,因为如果它真的需要8毫秒我不会注意到延迟,但我确实注意到了。我要说它需要大约300毫秒。

This returns values of around 8 ms. I know it takes longer to load an display an image because if it really took 8 ms I wouldn't notice the delay, but I do notice it. I'd say it takes about 300 ms.

加载大图像时FPS也会急剧下降。我正在使用enterFrame事件对此进行监控,并且在加载图像时,它会在1帧内打印大约0.3的值。

Also the FPS drop drastically when loading a large image. I'm monitoring this using an enterFrame event and when loading the image it prints values of around 0.3 for 1 frame.

Runtime:addEventListener( "enterFrame", myListener )

function onEnterFrame (event)
    print( display.fps )
end

加载时帧渲染需要很长时间,即使图像加载时间不到1/60秒。我想这意味着渲染是在其他地方异步发生的。

The frame takes a long time to render when loading, even when the loading of the image takes less than 1/60 of a second. I guess it means the rendering is happening asynchronously somewhere else.

那么,我如何衡量真正加载和显示图像所需的时间?

So, how can I measure the time it takes to really load and display an image?

推荐答案

由于Corona SDK是封闭源代码,我们必须使用文档和想象力。

Since Corona SDK is closed source, we'll have to use the docs and imagination.

我在这里看到三种可能性:

I see three possibilities here:


  1. Corona正在做它所说的,你的主观经验是错误的。

  2. Corona正在后台线程中加载图像,因此对 display.newImageRect 的调用是非阻塞的:它开始加载图像,并且然后继续当其他SDK(主要是基于javascript的)发生这种情况时,你会得到一个可以在图像对象上使用的准备回调,但我在文档中找不到这样的东西。

  3. Corona快速加载图像,但需要之后的额外工作。例如,它会产生大量垃圾,必须进行垃圾收集。所以图像加载得很快,但是这种额外的工作会减慢应用程序的速度。

  1. Corona is doing what it says, and your subjective experience is wrong.
  2. Corona is loading the images in a background thread, so the call to display.newImageRect is non-blocking: it "starts" loading the image, and then continues. When this happens in other SDKs (mostly javascript-based ones) you get a "ready callback" that you can use on the image object, but I could not find such thing in the docs.
  3. Corona loads the image quickly, but requires "extra work afterwards". For example, it generates lots of garbage which has to be garbage-collected. So the image gets loaded fast, but then this "extra work" slows down the app.

我的赌注是3.但是这个并不重要。独立于这些选项中的哪一个导致减速,它们可以以相同的方式解决:不是在绘制图像之前加载图像,而是必须预加载它们。

My bet is on 3. But this doesn't really matter. Independently of which one of these options is causing the slowdowns, they can be solved the same way: instead of loading the images right before you draw them, you have to preload them.

我不使用Corona SDK,但快速google指向我故事板模块,特别是 storyboard.loadScene

I don't use Corona SDK, but a quick google pointed me to the storyboard module, in particular to storyboard.loadScene.

创建一个新场景,列出你需要的所有图像,并在显示之前加载它 - 这样就可以提前完成图像加载,而不是减慢速度你的应用。

Create a new scene, list all the images that you need on it, and load it before showing it - that way image loading will be done in advance, not slowing down your app.

这篇关于测量Corona SDK中图像加载的经过时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆