Sign in to follow this  
redseadragon

C++ vs AS3: speed wise

Recommended Posts

EDIT: I'm just going to clarify here that I am not making a Diablo clone - this is just an example to make sure everyone is on the same page. Let's say I wanted to make a Diablo clone (because I have an illogical multi-billion dollar bet with a cute deep sea diving car salesman from France) : how much faster would the game be if it were made in C++ v.s. AS3? Now, that's a bit of a loaded question, since there is a lot I could do to bloat the code - so let's say that they are both well written. The AS3 code would use methods like bliting for images instead of making everything a movie clip, exc... Also, the AS3 project will be run as an Adobe Air program, not on the internet. The only rough estaminet I have been able to find is from the adobe web site when they are speaking about Alchemy (it is a project that allows you to compile and run C and C++ code on the ActionScript Virtual Machine so it ends up working as one program): "performance can be considerably faster than ActionScript 3.0 and anywhere from 2-10x slower than native C/C++ code." - http://labs.adobe.com/technologies/alchemy/ Or in other words they are saying: C/C++ can be considerably faster than ActionScript which is 2-10x slower. At least, when it is run on our virtual machine... It would be great to hear from everyone on this matter - especially if you have some personal experience with this. [Edited by - redseadragon on November 25, 2009 3:54:58 PM]

Share this post


Link to post
Share on other sites
Diablo is 13 years old. Diablo 2 is 9 years old. What do you plan on doing to your 'clone' that would necessitate using the faster language, if such a thing were quantifiable? Because 2D isometric games aren't exactly resource intensive these days unless you throw in a bunch of special effects.

What I mean is, it probably doesn't matter which language would produce faster code for this kind of project so try to make your decision based upon what you have the most experience with.

Also try to avoid using any copyrighted material when making this 'clone' as you are liable to get sued.

Share this post


Link to post
Share on other sites
How about you write an AS3 script that blits arbitrary number of sprites. Then test that on several machines, and see where things break.

Note that blits were never solved performance-wise in C++. They are simply done via GPUs these days, taking CPU out of the equation.

Quote:
how much faster would the game be if it were made in C++ v.s. AS3
It would be exactly as fast. Why? Because if a game is playable at speed X, then running it 25 times faster makes no sense. Imagine mobs running across the screen in 0.4 second instead of 4 seconds.

As for the other type of "fast" - again irrelevant. If you are using AS3, and there is a bottleneck, do less, reduce image size, reduce sprite resolution, etc... Everything is a compromise.


Now go write some blit code and time it.

Share this post


Link to post
Share on other sites
Is it slower? Yes. ActionScript running inside a flash player is slower than C++ code that has been compiled to run native on your target platform.

Is the speed of the language important for your particular game? Probably not.


You will still need to avoid doing stupid things like picking slow algorithms and consuming all your memory, but that is true no matter what language you pick.


Diablo is old. I remember playing it on a 66Mhz machine with 16MB of memory. Today you are probably on a multi-core 2GHz machine with several gigabytes of memory. Compared against a good machine today, you're looking at 60x or 120x the processor power and 250x the memory. You should have no problem implementing it with ActionScript.

Share this post


Link to post
Share on other sites
I'm just going to clarify here that I am not making a Diablo clone - that was just an example to make sure everyone was on the same page. I could have said "Baldor's Gate clone" or just "2D isometric single player game that isn't on the internet" - but then it wouldn't have the word "clone" in it and people's minds might go wandering :) Unfortunalty, this also means that there is no multi-billion dollar bet with a cute deep sea diving car salesman from France... awwwwwww...

Sorry for the confusion.


On another note, would anyone like to lend me a cute deep sea...?

Share this post


Link to post
Share on other sites
[Quote: Antheus]It would be exactly as fast. Why? Because if a game is playable at speed X, then running it 25 times faster makes no sense. Imagine mobs running across the screen in 0.4 second instead of 4 seconds. [/Quote]

I'm just talking about how quickly C++ computes the same code as opposed to AS3.

[Quote: Antheus]Now go write some blit code and time it.[/Quote]
I'm not going to write a blitting code for C++ today because I don't know that language well enough. And as I'm not very good with code, it would take me quite a while to learn it all just to find out if I wanted to use C++.

Share this post


Link to post
Share on other sites
Impossible to tell

I do have a lot of experience in both languages, and yes AS is a lot slower for most(all?) things
how much slower?
ballpark figure off the top of my head dont be surprised if some things are ~1000x slower

Share this post


Link to post
Share on other sites
I read a nice article today on Adobe Alchemy at http://www.automatastudios.com/2008/11/21/understanding-adobe-alchemy/ which made some interesting points:


"In fact, because LLVM does a lot of optimizations, whereas Flash and Flex have no optimization step built into their compilers, Alchemy code manages to overcome a lot of it is overhead just on its own.

Now, what are these operations that Alchemy does so well? Memory access and function calls. Alchemy compiled code utilizes new bytecodes added to FP10 for working with ByteArrays – which as you’ll remember are what make up the “RAM” in Alchemy. Function calls are faster because in ActionScript function calls require that their parameters be “boxed” and “unboxed” into and out of objects for each call. Alchemy code doesn’t have to do this."

Hopefully I will find more bits of info like this over time.

Share this post


Link to post
Share on other sites
Before you code whatever game you're making, make sure that you analyze your overall goals for the game before attempting to choose a programming language for it. Often times, you'll find out that speed isn't necessarily the defining factor, but the flexibility of the software you have chosen.

Is C++ going to be faster than AS3? Yes, because it works closer to the hardware and you have a lot more capabilities at your fingertips. But with that said, you'll have to do more setup and deal with people running on different operating systems and having different drivers.

AS3 is easier to use to quickly get a game together. And given that Flash runs on nearly every browser available, it's easy to get people to play it. Flash can gain a performance increase if you use bitmap art instead of vector art because bitmaps renders faster. However, bitmaps also take up more memory and will drastically increase your file size. You also can't use the right mouse button unless you compile your game as an Adobe AIR application.

There are a host of advantages and disadvantages for both. I would suggest studying them closely and basing your decision on those in addition to the performance differences.

Share this post


Link to post
Share on other sites
I could be mistaken, but I believe everyone is side-stepping the OP's actual question.

The quote on adobe's website is referring to alchemy being 2-3x slower then optimal native C++ AND is "quite a bit" faster then well written action script. This would easily be enough to power a game that is slightly better then PSX era, at least while running on most modern computers (presuming everything is coded very well, alchemy used where appropriate, etc. So yes, go ahead and plug away at your SNES era RPG and have fun with it. In fact, flash is even getting better at 3d, and has some native functions for that. A few popular wrappers are available online which really show the power of the new flash10. There were even some 3d racing games that run fairly smoothly. I have been working on flash TBS game for a while now, and even had smooth skeletal animation going.

Be really careful with memory management in alchemy. I have noticed that the VM doesn't quite hold up well when it uses allot of heap memory. If you have access to adobe air, I would suggest hijacking the built in SQL engine to handle the extensive memory management. Not really sure how well that binds to alchemy though, Im experimenting with it now.

As far as right click context menus in the browser as someone else pointed out. It is quite easy to get around that using a little bit of clever javascript. I wrote a small jquery extension that does just that. Hover a little 2px shim with 1% transparency over the mouse cursor, and override its onclick. Works on all the major browsers (screw operah).

Richard

Share this post


Link to post
Share on other sites
That "todays opinion" about the actual HWs sucks in MY opinion, "thats not important, todays HW are awsome"...Thats doing a new generation of worse programmers eva..buts thats MY opinion...

Those old games like half life and age of empires, jesus, they run without problems on a P4 1.6Ghz with 256MB...But when you try to play an indie game on a machine like that, woahhhh, a game 500 times simpler runs all laged at 5-10fps..but who cares, nobody have a machine like that right?

I dont know about you, but that philosophy make me sick, Im not expert neither have experience enough to say those things, maybe Im exaggerating, but its like sayng "why you are doing it in c++, its all donne to you in java", but just remember that when ppl nows something is ASM implemented EVERYONE fills perfectly safe and better about using it...

my english is terrible, sorry about that..

Share this post


Link to post
Share on other sites
Quote:
Original post by Icebone1000
Those old games like half life and age of empires, jesus, they run without problems on a P4 1.6Ghz with 256MB...But when you try to play an indie game on a machine like that, woahhhh, a game 500 times simpler runs all laged at 5-10fps..but who cares, nobody have a machine like that right?


I have to mention that those programmers got paid for good work, while indie programmers do it just for fun. There is no point in optimizing every single frackin' (excuse my BS slang) algorithm if the average user has enough resources for the bad version anyway. Not everyone really cares about implementing the "best" (whatever it may be) way to solve a problem, because they care about actually making a game and not getting caught in details. Do you see any player being excited that game xyz did use some awesome way to implement collision detection? Or that they squeezed out some cpu-cycles by hand-writing matrix multiplications using SIMD instructions? I really doubt it.

Even professionals don't care about speed/resources ALL the time. They care when it's necessary for the product to be sold (or to run at all :P), but not in general.

Share this post


Link to post
Share on other sites
even if both c++ and actionscrip uses cpu at the same efficency (which is false) since as3 does not use gpu (as far as I know) capabilities of it would be still poor.

Share this post


Link to post
Share on other sites
Quote:
Original post by phantom
yes, because C++ totally uses the GPU... wait, wut?


no it can't but you can use a graphic library with c++. with actionscript you don't have much choice

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this