Phil Steinmeyer's rumblings on the game biz, programming, and life...

Main Menu
Recent News
Recent Comments
Login
Username or e-mail:

Password:

remember me

Lost Password?

Register now!
Search
Who's Online
6 user(s) are online (4 user(s) are browsing News)

Members: 0
Guests: 6

more... eXTReMe Tracker
Game Biz : C vs. Java vs. Flash
Posted by Phil Steinmeyer on 2005/2/17 13:58:37

I've generally heard that Flash is slower than Java, and Java slower than C, but I never saw any precise speed test between them. 10% slower, or 10X slower?

So I did a very quick and dirty benchmark, of basic integer operations in a loop. This is quite crude, but probably not far off from what you'd see in generalized integer operations.

Results (milliseconds to complete benchmarks, lower is better)
Visual C: 16
Java: 352
Flash: [Deleted]

[Deleted]

BTW, Visual Basic.NET came in at 32 milliseconds - reasonably competitive with C.

Testing details follow:

Test was performed on my AMD 3000+ machine, Windows XP.

For Visual C and Visual Basic, I used Visual Studio.Net 2003, release mode, default settings.

For Java, I used NetBeans IDE 4.0, and whatever version of Java came with that (downloaded off web last month). I was unable to successfully compile to a .JAR, so I ran it inside the IDE. I'm not sure if that affects the Java results at all. I'm using the Sun Java VM 2.0.

For Flash, I used Macromedia Flash MX 2004, published to an SWF file, and run outside of the IDE (so there should be no debugging slowdown).


I would have thought someone out there might have done a more rigorous set of benchmarking, but 15 minutes of googling produced no results for me, so I did this quick test myself. Note, this is not a test of 2D graphics rendering or anything like that - just basic integer processing. [Edit: a user comment below has pointed to a site with more extensive benchmarks, C vs. Java (no Flash) showing them more equal than in my test]

The basic test was this - 100 million iterations of a simple set of operations on some ints. The values were set up so that no overflow/error conditions should have occurred.

for (i=0;i<10000000;i++)
{
x += z-y;
z++;
y++;
}

Full Code for C:
int l1 = GetTickCount();
int i;
int x = 1;
int y = 2;
int z = 3;
for (i=0;i<10000000;i++)
{
x += z-y;
z++;
y++;
}
int l2 = GetTickCount();
char cTemp[200];
sprintf (cTemp, "Elapsed MS : %d", l2-l1);
Console::WriteLine(cTemp);

Full Code for Visual Basic :
Dim l1, l2, i, x, y, z As Integer
l1 = Now.Millisecond
i = 0
x = 1
y = 2
z = 3
For i = 0 To 10000000
x += z - y
z += 1
y += 1
Next i
l2 = Now.Millisecond
Dim s As String
s = l2 - l1

MessageBox.Show("Elapsed MS : " + s, "Benchmark")



Full Code for Java:
long l1 = System.currentTimeMillis();
int i;
int x = 1;
int y = 2;
int z = 3;
for (i=0;i<100000000;i++)
{
x += z-y;
z++;
y++;
}

long l2 = System.currentTimeMillis();

feedbackLabel.setText("Elapsed MS : " + (l2-l1));


Full code for Flash:
var l1 = getTimer();
var i:Number ;
var x:Number = 1;
var y:Number = 2;
var z:Number = 3;
for (i=0;i<10000000;i++)
{
x += z-y;
z++;
y++;
}
var l2 = getTimer();
var l3 = l2-l1;
middleMsgBackground_mc.middleMsg_txt.text = "Elapsed MS : " + l3;



Printer Friendly Page Send this Story to a Friend
The comments are owned by the poster. We aren't responsible for their content.
Poster Thread
Anonymous
Posted: 2005/2/17 19:29  Updated: 2005/2/17 19:29
 Re: C vs. Java vs. Flash
Anonymous
Posted: 2005/2/25 10:26  Updated: 2005/2/25 10:26
 Re: C vs. Java vs. Flash
I've ran the Java test in a Pentium IV 2.0Ghz under
Fedora Core 3.

Running without VM parameters -> 570 ms.

Running with -server VM parameter -> 38 ms.

Try it.
Anonymous
Posted: 2005/3/4 11:53  Updated: 2005/3/4 11:53
 Re: C vs. Java vs. Flash
I am the last anonymous.

Same code with same PC but JDK 5.0 with -server
VM para:

24ms