speed problem (compare to java)

5 posts

Flag Post

Hi I’m a flash newbie but am an experienced developer.

I finally am looking into converting some of my java projects to flash. For my first project I ported my voter project http://www.cheesygames.com/voter which was originally done in java.

The problem is that the flash version is much slower than the java version.
I created a test page (http://www.cheesygames.com/voter_test) to show the speed difference voter along with the source code for the project.

At this point i think I’m just not doing things in a flash friendly way which is slowing things down.

If anyone can provide any pointers I would appreciate it.

 
Flag Post

The problem is not Flash, its your coding methodology. It looks like your only using 1 EnterFrame event to update the blocks. This means 1 will only see 1 change based on the frame rate you have set. It doesnt look like are stressing flash at all.

1) Increase your framerate
2) Use a loop to run several updates per EnterFrame.

Heres your code, updated to run 3000 iterations per EnterFrame event. As you can see, its fast. It could push several times that amount per EnterFrame if you desired.

http://www.jacobcorreia.com/misc/swf/voter.html
http://www.jacobcorreia.com/misc/swf/voter.as

An alternate and possibly faster way would be to create a much smaller bitmap, enlarge it so the pixels are blocky, and then use the fast setPixel() method on it. You should get even better performance out of that (for this particular setting).

 
Flag Post

Ahh I see – so enterFrame will not execute quicker than the set FPS. I was thinking it would just fire as often as it could.

So does this mean your code is doing 3000 * 31 (fps) = 2,883,000 iterations per second and my original code was doing 31 iterations per second?

I’ll have to play with the setpixel idea as well. I just assumed a pixel would always be single pixel rather than being able to zoom in on it.

Thanks for the info I appreciate it.

 
Flag Post

so enterFrame will not execute quicker than the set FPS

Correct. The EnterFrame event fires every time flash enters a new frame, as its name implies. 31 fps = 31 events fired per second.

So does this mean your code is doing 3000 * 31 (fps) = 2,883,000 iterations per second and my original code was doing 31 iterations per second?

I believe its 93,000 iterations per second, but ya you got the point.

 
Flag Post

That’s awesome, thanks for posting the code Coder.