C++ vs AS3: speed wise

Started by
13 comments, last by shultays 14 years, 4 months ago
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]
Advertisement
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.

C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) , Part 3 (decltype) | Write Games | Fix Your Timestep!

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.
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.
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...?
[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.

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.
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++.
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
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.
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.
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 &#106avascript. 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

This topic is closed to new replies.

Advertisement