(I've posted this in All About Scratch because I don't think any of this is *too* technical, and it's I think it will be useful to most Scratchers.)
UPDATE - 1/21/12 - Here I have more results with testing in Turbo Mode.
Introduction
The Flash Player has confused me for a very long time. What makes it so fast? Many games that were incredibly slow (in Scratch 1.4 and the java player) can now be played very easily in the Flash Player. For example, check out Scratch Kart Demo by RHY3756547. In the java player, it's unplayable (doesn't actually load). In Scratch 1.4, it's playable, but doesn't live up to it's full potential. In the flash player, it runs at a much greater speed, and is very enjoyable.
Experiment
What I decided to do is set up an experiment. My purpose was to find out what features of the flash player are faster than Scratch 1.4 or the java player. My background research was... well there wasn't any xD. My hypothesis was that the flash player would be faster, as that is what I have found in my general experience. My procedure was to create a project that tested the different features of Scratch, and to test it in all 3 platforms (flash player, java player, and Scratch 1.4).
This is the project with the tests. The 7 tests were all within repeat (100) blocks, while using the timer to determine how long each one took. I repeated the project 3 times in each platform and averaged the times together for an accurate result. Inside the repeat (100) blocks, I had the following:
- nothing
- broadcast and wait (with an accompanied "when received" block)
- pen drawing in a square
- rotating square
- increasing size of Scratch Cat
- increasing ghost effect of Scratch Cat
- stamping Scratch Cat at random positions
Results
Here are my results:
Scratch 1.4
Test 1: 2.502 seconds
Test 2: 7.504 seconds
Test 3: 2.501 seconds
Test 4: 2.646 seconds
Test 5: 2.545 seconds
Test 6: 2.502 seconds
Test 7: 2.588 seconds
Java Player
Test 1: 3.000 seconds
Test 2: 6.000 seconds
Test 3: 3.000 seconds
Test 4: 3.000 seconds
Test 5: 3.000 seconds
Test 6: 3.000 seconds
Test 7: 3.000 seconds
Flash Player
Test 1: 0.000 seconds
Test 2: 3.276 seconds
Test 3: 3.287 seconds
Test 4: 3.288 seconds
Test 5: 3.316 seconds
Test 6: 3.315 seconds
Test 7: 3.308 seconds
Conclusion
Let's start with Scratch 1.4. A repeat block takes about 0.025 seconds for one loop, and a broadcast block takes 0.05 seconds to be sent and received. These are the underlying causes of lag in Scratch. Apart from that, test 4, 5, and 7 have a bit of a difference, but nothing important.
Now let's take a look at the java player. A repeat block takes about 0.03 seconds for one loop, and a broadcast block takes 0.03 seconds to be sent and received. The results of these tests were very consistent. So, the broadcasts are faster than those in Scratch 1.4, but the repeat blocks are slower.
Lastly, the flash player. The repeat block takes 0 seconds for one loop, and -- wait what!? It seems that the flash player is smart enough to see through this trick, and simply ignores the empty repeat block. The rest of the results are fairly similar, varying from 3.275 to 3.325 seconds.
This is confusing however, because these times are greater than those of Scratch 1.4. Yet the flash player is faster? Clearly my hypothesis is wrong. What I have concluded is that I have done a lot of rendering which is slower than Scratch 1.4, but I have not tested calculating, which I guess is faster. I am most likely going to make another experiment to test this.
Well that's the end! I hope you've learned a bit about the flash player. If you have any comments about the results, or suggestions for the next experiment (to test calculations and long scripts), then please do post!
And of course, Scratch On!
Last edited by Lucario621 (2012-01-21 16:33:49)
Offline
catfan8 wrote:
Well the one case when the flash player is faster is the broadcast and wait, which is used a lot more than those other functions like ghost effect or nothing
A yes, that's right, I didn't catch that. I would still say that ghost effect is a fairly useful feature, even though it's a bit uncommon. As far as the "nothing", that's important because "nothing" applies to *every script*. The time to move 10 steps 100 times is the time it takes to do nothing 100 times, plus the time it takes to move 10 steps 100 times. So if the time to do nothing was always 0, then our projects would be 0.025 faster per frame in Scratch 1.4, which may seem like a little, but it's actually quite a lot. Sorry if I didn't explain it that well.
Offline
Lucario621 wrote:
catfan8 wrote:
Well the one case when the flash player is faster is the broadcast and wait, which is used a lot more than those other functions like ghost effect or nothing
A yes, that's right, I didn't catch that. I would still say that ghost effect is a fairly useful feature, even though it's a bit uncommon. As far as the "nothing", that's important because "nothing" applies to *every script*. The time to move 10 steps 100 times is the time it takes to do nothing 100 times, plus the time it takes to move 10 steps 100 times. So if the time to do nothing was always 0, then our projects would be 0.025 faster per frame in Scratch 1.4, which may seem like a little, but it's actually quite a lot. Sorry if I didn't explain it that well.
Great, Now I'm curious and have to test some of this! Thanks a lot.
Offline
My good friend cpumaster930 recently commented on my project telling me that when using turbo mode on the flash player, the times were less than 0.01 second for each. This reminded me that I didn't test the turbo mode for Scratch 1.4 and the flash player. Here are my results:
Scratch 1.4 (Turbo Speed)
Test 1: 0.003
Test 2: 0.033
Test 3: 0.039
Test 4: 0.340
Test 5: 0.147
Test 6: 0.015
Test 7: 0.188
Flash Player (Turbo Mode)
Test 1: 0.000 seconds
Test 2: 0.000 seconds
Test 3: 0.010 seconds
Test 4: 0.000 seconds
Test 5: 0.000 seconds
Test 6: 0.000 seconds
Test 7: 0.010 seconds
What does this mean? The Flash Player is much better at handling turbo mode than Scratch 1.4. This is why graphical projects that involve raycasting and other rendering work very well in the flash player. For example, look at Full Raytracer by Canthiar. This works OK in Scratch 1.4, but it is much faster in the flash player.
Last edited by Lucario621 (2012-01-21 14:09:21)
Offline
catfan8 wrote:
Well the one case when the flash player is faster is the broadcast and wait, which is used a lot more than those other functions like ghost effect or nothing
You could sticky it!
Offline
Chrischb wrote:
If there were a featured thread thing I'd nominate this
There are stickies and iTopics (I haven't forgotten -- check the old block lib).
Offline
plus, list operations are SOOOOO much faster in flash player
this project
scratch 1.4: 7.1/1.54
java: 6
flash: 3.3/0.016
Offline
roijac wrote:
plus, list operations are SOOOOO much faster in flash player
this project
scratch 1.4: 7.1/1.54
java: 6
flash: 3.3/0.016
Interesting test! You're right. Another examle is this project that I made two years ago; a lot faster in the flash player than in Scratch 1.4.
Offline
Hm, that's very interesting indeed. Especially the fact that only the Flash player takes no time at all to execute nothing.
Offline
RedRocker227 wrote:
Hm, that's very interesting indeed. Especially the fact that only the Flash player takes no time at all to execute nothing.
I agree, I was never expecting that.
Offline
Indeed, the Flash player seems to run Scratch project faster and better than the current version of Scratch (1.4).
Which makes me wonder about how well projects are going to run in Scratch 2.0 (the offline version).
Offline
cheddargirl wrote:
Indeed, the Flash player seems to run Scratch project faster and better than the current version of Scratch (1.4).
Which makes me wonder about how well projects are going to run in Scratch 2.0 (the offline version).
Probably pretty much the same, but a tiny bit slower because it'll be drawing the blocks too.
I have big plans for ScratchCraft if the editor runs fast enough to make a level in.
Offline
cheddargirl wrote:
Indeed, the Flash player seems to run Scratch project faster and better than the current version of Scratch (1.4).
Which makes me wonder about how well projects are going to run in Scratch 2.0 (the offline version).
To my knowledge, they will both be using flash, so it shouldn't make a difference. (Perhaps only slightly faster offline?)
EDIT: Reading Dawgle's post, he has a good point. The block rendering will probably slow down the offline version.
Last edited by Lucario621 (2012-01-23 16:51:31)
Offline
Hm... What about doing every block in scratch (yes, I do know how hard that would be) and seeing what kind of blocks work best in each. Like you said, flash seems to be the calculating one. My best guess for java would be display, and I think that scratch would be right in the middle. That way, you could make one of those testers to see what the project is being run in, and make it so that you have to use the best one.
Offline