I try to do a bunny benchmark in OpenFL
The thing is that I can’t get more than 1,000 bunnies at the same time.
Obviously I’m doing something wrong, but I have no idea what.
I have a tile sheet with two images, the background grass and the bunny.
Two sprites, one for the world and one for the GUI.
And two text fields, that are child of the gui sprite.
I create the tile rects for each image, set the stage quality to low, format texts, blah blah, and added one enter frame event.
In the enter frame I get the delta time using Lib.getTimer(). Then maybe create some bunnies, and move them.
Finally I add all grass data than then bunny data into an Array, clear the world.graphics and in one call draw all tiles of bunnies and grass. And update the text to show current fps and amount of bunnies.
I only have 1 enter frame entry in the program. Basically I have no idea what I’m doing wrong.
This is the windows CPP target. Here is a screen shot: http://imagizer.imageshack.us/a/img673/2340/EchBlN.jpg
Any help would be appreciated.
Hard to tell without seeing all the code, but you might have an issue with GC thrashing. Only way to know for sure is to profile the app, but recreating an array with thousands of elements per frame (
Bunnies.draw()) could be the issue. Look at how the tilelayer lib handles the drawList.
First, thank for the help.
Here is all the code, is pretty short actually. http://imageshack.com/a/img673/2342/u3OWIs.jpg
Mmm. Now that I think about it, it’s probably not the best order, main is in the centrer.
Main is not full, but the other things are initializations and boring configurations.
I profile the code (found how to add telemetric to the swf). http://imagizer.imageshack.us/a/img538/6248/e8BHTq.jpg
For what I can see, the rendering is killing it, takes half the time.
Garbage collector is high, but only not that high.
Anyway, I will create a DrawList class to reduce garbage collection and the time of bunnies.Draw (specially that concat) and come back to tell how it was.
Make a DrawList class that overrides an array, so no new array is created per frame. array.concat was being a killer.
Now I get 30,000 bunnies at 45 fps.
You can also
openfl create BunnyMark to duplicate a BunnyMark sample, comment things in the main class to change the type of test, the
drawTiles test should perform the best on native targets
I just try it. The batched version of drawTiles was indeed the fastest with 22,000 bunnies.
I took out the pirate, the alpha, the scale and the moving background.
For flash target the fastest was copyPixels with 2,500 bunnies.