Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Speed test: Case vs loop, for vs until vs endwhile vs loop

Author
Message
Daniel TGC
Retired Moderator
17
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 7th Sep 2015 17:01 Edited at: 7th Sep 2015 17:23
Hi guys,

I'm attempting to optimize my game, and as I was doing so a fairly obvious question occurred to me... Which technologies are faster in App Game Kit? Do different devices affect this as well?

So I've written a little program (if you see a way of improving it please let me know!) that tests the following technologies.

Case Statements
If Statements
For next loop
Until loop
EndWhile loop
Do loop

I've further divided this down further.

Decision making with binary options
Decision making with dual deca (20) options

Case statements are straight forward.
If statements can be used in several different ways so i've broken this down into further sections.

If Else Endif
If EndIf
If Elseif Endif

With the binary option, we can do a simple if, else, endif. Obviously this won't work for 20 options but it will compare the If statement technology to the Case statement technology in a "one or the other" situation. The simple else is abandoned for the 20 options method.

The loops are straight forward, they have a fixed value to reach and then they terminate. This is for direct comparison with FOR and NEXT. There are clearly going to be situations where Until and While can be triggered earlier in a loop meaning less cycles expended. But having said that in a head to head, I wondered which is faster.



I also tallyed up all the times which equates to a benchmark.

Basically the lower the value the faster the machine.
Daniel TGC
Retired Moderator
17
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 7th Sep 2015 17:10 Edited at: 7th Sep 2015 17:11
My results for a Lenovo T420 i5 powered laptop. The results are quite interesting.

Attachments

Login to view attachments
Crazy Programmer
AGK Developer
19
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Lost in AGK
Posted: 7th Sep 2015 17:32
I was almot identical to your outcome.

My Benchmark was 71.47.

Running on, Windows 10 64bit, I5, 8gb ram, 500gb hardrive

Beta Test Age of Knights:https://play.google.com/apps/testing/com.CrazyProgrammerProductions.my_AgeOfKnights
Download JellyFish Dive:https://play.google.com/store/apps/details?id=com.CrazyProgrammerProductions.my_JellyFishSwim
Daniel TGC
Retired Moderator
17
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 7th Sep 2015 17:34 Edited at: 7th Sep 2015 17:38
Thanks Crazy Programmer, it\'s good to know the i5 series vary little.

This is a test of my fastest android device. The nVidia Tegra 4 based MAD Catz M.O.J.O.

Attachments

Login to view attachments
Daniel TGC
Retired Moderator
17
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 7th Sep 2015 18:02 Edited at: 7th Sep 2015 18:03
This is the results for my HP Steam 7 tablet. It has windows 10 (full edition), an Atom Z3735 quad core processor @ 1.33ghz, 1gb RAM, and 32gb eMMC HDD.

Attachments

Login to view attachments
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 7th Sep 2015 18:09
Useful tests, thanks for sharing.

I'm not sure the comparison of the CASE statement is a fair one, compared to IF and IF/ELSEIF statements.

For the IF statement, you are always executing 20 clauses, irrespective of the value.

For the IF/ELSEIF and CASE statements you only execute all of the statements about 5% of the time...in this scenario. But in the real world it would be even less if you structure the code correctly.

It gets complicated further when you structure your game correctly with CASE statements. for example if I have 3 states - STARTGAME, PLAYING, ENDGAME, then I would not place the CASE statements in that order (even though it makes sense chronologically). I would use the order PLAYING, STARTGAME, ENDGAME. 99.9% of the time I would stop at the first CASE. If I used the original order then 99.9% of the time I would process 2 CASEs.

So...when comparing these options, consider the design of you game and factor in the frequency at which you will process multiple CASE statements across the full list of scenarios.

Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Daniel TGC
Retired Moderator
17
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 8th Sep 2015 16:28 Edited at: 8th Sep 2015 16:35
I absolutely agree. Cases can be optimized so that the more commonly generated numbers are toward the top of the list.

In cases of simple program run, program menu, program start ( in that order ) then cases can be organised in that way.

So the question I ask myself, is if an if statement was structured in the same way would it make a difference? (not tested that yet)

I'm dealing mostly with procedurally generated data however, so I can't often predict what the values will be. However there is a way of making this test fairer I think and that's to reset the random number generator before every test. This means that the exact same numbers are being generated and pushed through the if and case statements. Same sequence should make the test fairer.




Here's a retest of my i5 t420 laptop.

Attachments

Login to view attachments
Conjured Entertainment
AGK Developer
18
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 8th Sep 2015 17:23 Edited at: 8th Sep 2015 17:35
Quote: "It gets complicated further when you structure your game correctly with CASE statements. for example if I have 3 states - STARTGAME, PLAYING, ENDGAME, then I would not place the CASE statements in that order (even though it makes sense chronologically). I would use the order PLAYING, STARTGAME, ENDGAME. 99.9% of the time I would stop at the first CASE. If I used the original order then 99.9% of the time I would process 2 CASEs."

Good point BatVink
I don't think the results will vary enough to change my coding preferences.
The structure of the code is far more important than the commands being used when optimizing.
A loop is a loop is a loop, it all comes down to how it is managed to avoid unnecessary repetition.


On a side note:
cycles = 2147483647 / 100 * 2

isn't that the same as ...
cycles = 2147483647 / 50

... or simply 42949673 (42949672.94)

Why is the math being done there in the initialization if it is a fixed number?


Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1
haliop_New
User Banned
Posted: 8th Sep 2015 19:06
Here is mine (2nd test- Newest)

Laptop

i7 - 3630QM 2.40 GHZ
8 GB RAM
Windows 10 64 bit
SSD 256 GB

i dont know if the GPU plays here but.. well..
GTX 670M



i wonder how it scores less then the i5 .. but it might be that my i7 is of an old gen.
Daniel TGC
Retired Moderator
17
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 8th Sep 2015 19:08 Edited at: 8th Sep 2015 19:13
@Conjured Entertainment: Yes it can be expressed that way. I was playing around with numbers, dividing it by 100 took longer than I wished to wait so I just cut it in half. I was thinking more along the lines of time passing rather than choosing a specific target value. You'll find that little quirk in a good number of my past programs lol. It's just laziness on my part.

@haliop_New thanks for the results, it's nice to know the i7's behave in the same way. I wouldn't have thought GPU played much of a role in this but I couldn't say for certain.

I've swapped some of the more complex loops from for to until and am seeing a improvement in the code, also swapping the binary from case to if else endif, and then the long number checks from if to case has also increased the speed of my program nicely. So these tests where worth doing, I'm generating worlds about 45 seconds faster than I was before just with those changes.

Note: If anyone has an AMD chip I'd love to see those results as well, and an iOS device. My apple developer subscription has run out for the moment!

Login to post a reply

Server time is: 2024-05-04 15:47:21
Your offset time is: 2024-05-04 15:47:21