Highlighted

Why is AS3 more than 4 times slower than c, c# or Java?

Engaged ,
Jul 18, 2018

Copy link to clipboard

Copied

Hi,

I understand that AS3 is going to be slower than c of course, BUT why 4 times slower. That seams like too much with a simple test like this where no object or string manipulation is happening, only function call and integer comparison, increment plus one modulo operator.

I have a situation in Box2D where when you have a lot of complex dynamic objects with a lot of fixtures Box2D is calling one particular function like 7000, 10000 and even 20000 times. That is why I have design a very simple test to only test function call performance.

I have created this test for ActionScript 3, C, C#, Java and ActionScript.

This is the code for ActionScript 3:

https://pastebin.com/Hy9Kcc4h

Test completes on my machine in 15 seconds. I am using AIR SDK 30, Windows 10 and Flash Builder 4.7.

Also this result is for release build. Result is the same for Win 32 bit Captive release build and release build swf run from Flash Standalone Player (not debug player);

This the code for C:

https://pastebin.com/h6j6VXtA

I have used MinGW compiler. Value of CLOCKS_PER_SEC on my machine is 1000

This test completes for about 4 seconds. I have tested this by running compiled exe file from the command line.

This is the code for C#:

https://pastebin.com/66eGGXE0

I have used Visual Studio Express 2017. I have created console application. On my machine this test completes for about 2 seconds. Which was very surprising because it seams faster than pure C. I tested this by running dotnet FunctionPerformanceTest.dll in the command line.

This is the code for Java:

https://pastebin.com/RwKSUDQs

This was the biggest surprise for me because this test completes in about 1 second which is the fastest of all tests. I run this by running java FunctionPerformanceTest in the command line.

This is the code for JavaScript:

https://pastebin.com/h6zQeBWu

This was of course the slower test of all. It completes after about 29 seconds. I have run this from npm with node FunctionPerformanceTest.js command.

So I understand that Action Script 3 is going to be slower than C or Java but why is slower more than 4 times?

Does this seams like too much for you as well?

Will there ever be any optimizations to speed things like this in AS3?

TOPICS
Development

Views

402

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Why is AS3 more than 4 times slower than c, c# or Java?

Engaged ,
Jul 18, 2018

Copy link to clipboard

Copied

Hi,

I understand that AS3 is going to be slower than c of course, BUT why 4 times slower. That seams like too much with a simple test like this where no object or string manipulation is happening, only function call and integer comparison, increment plus one modulo operator.

I have a situation in Box2D where when you have a lot of complex dynamic objects with a lot of fixtures Box2D is calling one particular function like 7000, 10000 and even 20000 times. That is why I have design a very simple test to only test function call performance.

I have created this test for ActionScript 3, C, C#, Java and ActionScript.

This is the code for ActionScript 3:

https://pastebin.com/Hy9Kcc4h

Test completes on my machine in 15 seconds. I am using AIR SDK 30, Windows 10 and Flash Builder 4.7.

Also this result is for release build. Result is the same for Win 32 bit Captive release build and release build swf run from Flash Standalone Player (not debug player);

This the code for C:

https://pastebin.com/h6j6VXtA

I have used MinGW compiler. Value of CLOCKS_PER_SEC on my machine is 1000

This test completes for about 4 seconds. I have tested this by running compiled exe file from the command line.

This is the code for C#:

https://pastebin.com/66eGGXE0

I have used Visual Studio Express 2017. I have created console application. On my machine this test completes for about 2 seconds. Which was very surprising because it seams faster than pure C. I tested this by running dotnet FunctionPerformanceTest.dll in the command line.

This is the code for Java:

https://pastebin.com/RwKSUDQs

This was the biggest surprise for me because this test completes in about 1 second which is the fastest of all tests. I run this by running java FunctionPerformanceTest in the command line.

This is the code for JavaScript:

https://pastebin.com/h6zQeBWu

This was of course the slower test of all. It completes after about 29 seconds. I have run this from npm with node FunctionPerformanceTest.js command.

So I understand that Action Script 3 is going to be slower than C or Java but why is slower more than 4 times?

Does this seams like too much for you as well?

Will there ever be any optimizations to speed things like this in AS3?

TOPICS
Development

Views

403

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jul 18, 2018 0
Enthusiast ,
Jul 18, 2018

Copy link to clipboard

Copied

when you say something complete in N seconds
is that a test that ran only once?
is that the average of few hundred tests? in the same run? in multiple run?

do you "do things" on the same machine when you are running those tests?

did you try running the tests isolated on another machine, a VM?

When you say "this was off course the slower test of all" about JavaScript
many could argues that JS should be faster than AS3

actually being 4x times slower than C is quite good for performance sake

but to be honest all that, like that, is quite useless

you should not care about raw performance that much

or at least you're approaching it the wrong way

because you mention Box2D I guess you're making a game
and raw performance itself will not solve all your problems

see it like video streaming online, if today you can stream 1080p,

if a machine can not cope with it, the stream can goes to 720p or lower

Even if you had C++ speed all the time you would still have to reduce/shrink/cheat/etc.

to manage performance

so I would say do read this
Performance-tuning Adobe AIR applications | Adobe Developer Connection

the approach measure / analyse / modify is imho the right one

and as mentioned there

Broadly speaking, analysis can lead you to one of two kinds of changes: design or code.

my point is just saying: you don't care if AS3 is 4x slower than C++

or you don't care to run a function 20000 times

what you do care is to set a metric like "the transition between A and B need to be smooth"
or "not freeze 4 seconds" etc.

at best, optimizing some code will be enough, at worst you will have to change the design

to fit your metrics (assuming those are not crazy)

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 18, 2018 0