Results 1 to 10 of 10

Thread: Speed of C# vs C++

  1. #1
    Member
    Join Date
    Aug 2003
    Location
    Wimbledon
    Posts
    141
    Thanks
    0
    Thanked
    0 times in 0 posts

    Speed of C# vs C++

    Somebody was asking me how fast C++ was compared to C# so I decided to try out a quick heath robinson test to simulate some maths intensive code.

    The tests were performed on my 2G p4 laptop with several runs for each.

    Visual C++ 6 Release ~ 820ms ( 1560ms Debug)
    Visual C++ 7 Release ~ 820ms ( 2864ms Debug)
    Visual C# Release ~ 1660ms ( 5718ms Debug)

    C++ is still king! and what have they done to VC7 debug builds?

    Code:
    	DWORD dwBefore = timeGetTime();
    	
    	double d1 = 0.727272;
    	double d2 = 0.26252;
    	double d3 = 343432.232;
    
    	for(int i=0; i < 100000000; i++)
    	{
    		
    		d3 = d1*d2;
    		d1 = d3*d2;
    		d2 = d2*d2;
    		d3 = d1*d2;
    		d3 = d3*d2;
    	}
    
    	CString szMsg;
    	szMsg.Format("Time taken: %dms", timeGetTime() - dwBefore);
    	MessageBox(szMsg);
    - Numbers picked at random.
    - Yes, this is a very narrow test.
    - C# code the same apart from functions used to get the time.
    - Timers resolution ~ 10ms.

  2. #2
    Registered User
    Join Date
    Mar 2004
    Posts
    9
    Thanks
    0
    Thanked
    0 times in 0 posts
    Arent they ocmpletely different languages tho? I thought C# is an ASP.netscriptiign language and C++ a normal fairly high level OOP, so i guess c# wouldnt even be compiled?

  3. #3
    Senior Member Kezzer's Avatar
    Join Date
    Sep 2003
    Posts
    4,863
    Thanks
    12
    Thanked
    5 times in 5 posts
    i thought C++ was a more advanced version of C# iirc. Hence why people want to learn C# before C++ on the occasion

  4. #4
    Goat Boy
    Join Date
    Jul 2003
    Location
    Alexandra Park, London
    Posts
    2,428
    Thanks
    0
    Thanked
    0 times in 0 posts
    They are not THAT different. Syntactically they are similar, tho from a philosophy point of view C# is a lot closer to Java than it is to C++.

    I ran the same example in Java, and got the following:

    751ms.

    That was on a P4 Mobile - 2Ghz laptop.
    "All our beliefs are being challenged now, and rightfully so, they're stupid." - Bill Hicks

  5. #5
    Junior Senior Member Aaron's Avatar
    Join Date
    Jul 2003
    Location
    London, England
    Posts
    1,516
    Thanks
    0
    Thanked
    1 time in 1 post
    Wow, that's crazy. I'd expect Java to be the slowest.

    thought C++ was a more advanced version of C# iirc. Hence why people want to learn C# before C++ on the occasion
    C# basically came about because Microsoft weren't happy with the speed of Java but liked the idea of a language designed for the internet/networks. The whole idea of Java was that it's platform-independent but Microsoft started building in a lot of Windows-specific functions into it's Visual Java compiler speed it up. The creators of Java, Sun, weren't too happy and sued Microsoft. Hence, Microsoft has come up with it's own language C#.

    From what I've seen, C# isn't really any more advanced than C++. If it's anything like Java then it's probably a nicer language to progam though.

  6. #6
    dgr
    dgr is offline
    Senior Member
    Join Date
    Jul 2003
    Posts
    621
    Thanks
    0
    Thanked
    0 times in 0 posts
    i really like the sound of c#, expect for the lack of cross platform use.

    garbage collection? speed? with c++ and java, you can only pick one .

    dgr
    dothan 745 @ 2.4ghz | 2gb Corsair XMS (2-3-3-6) | dual raptors (raid0) | ATI 9700pro | CM201 | dual lg 1810

  7. #7
    Member
    Join Date
    Aug 2003
    Location
    Wimbledon
    Posts
    141
    Thanks
    0
    Thanked
    0 times in 0 posts
    I think 'beenster missed a zero off the end

  8. #8
    Goat Boy
    Join Date
    Jul 2003
    Location
    Alexandra Park, London
    Posts
    2,428
    Thanks
    0
    Thanked
    0 times in 0 posts
    Java is often faster than C++. Tis true. Well, for certain things anyway.

    Here's how it works. Imagine all this stuff is running on a p4. When you compile a program in C++, unless you compile it specifically to use stuff that is specific to a p4, it will compile to be backward compatiable with the x86 instruction set. That means that it is often not executing in an optimised fashion.

    Ok, for Java, the code compiles identically, irrespective of what you are running the code on. Compiled java is compiled java - there is no way of setting specific processor flags as there are no specific processor flags - the java does not even "know" what processor it will be running on. The Virtual Machine, on the other hand, will know what processor it is running on. So when the VM runs the code, it says "OK, I'm running on a P4, here is my java, I will now optimise the Java for this processor and execute it". The result? Faster execution time.

    If Mart were to recompile the C++ code, and use certain compiler options that meant the code ONLY ran on a p4, I would expect it to out-perform java (but not by much).

    Clever, huh?

    Oh, and if anyone ever says that server side java is slow again on this forum, they will get a slap
    "All our beliefs are being challenged now, and rightfully so, they're stupid." - Bill Hicks

  9. #9
    dgr
    dgr is offline
    Senior Member
    Join Date
    Jul 2003
    Posts
    621
    Thanks
    0
    Thanked
    0 times in 0 posts
    i cannot agree tbh. java apps always feel "unresponsive" on my pcs.

    oh and compiling c especially for a system is SOOOOOOOOOOOOOOOO much faster than just using stardard x86 CFlags. i just recompiled my linux system with harder CFlags, and i swear kde loads twice as fast
    dothan 745 @ 2.4ghz | 2gb Corsair XMS (2-3-3-6) | dual raptors (raid0) | ATI 9700pro | CM201 | dual lg 1810

  10. #10
    Goat Boy
    Join Date
    Jul 2003
    Location
    Alexandra Park, London
    Posts
    2,428
    Thanks
    0
    Thanked
    0 times in 0 posts
    Quote Originally Posted by dgr
    i cannot agree tbh. java apps always feel "unresponsive" on my pcs.

    oh and compiling c especially for a system is SOOOOOOOOOOOOOOOO much faster than just using stardard x86 CFlags. i just recompiled my linux system with harder CFlags, and i swear kde loads twice as fast
    "and if anyone ever says that server side java is slow again"
    "All our beliefs are being challenged now, and rightfully so, they're stupid." - Bill Hicks

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. When is a speed camera not a speed camera?
    By DR in forum Automotive
    Replies: 40
    Last Post: 17-10-2006, 05:28 PM
  2. Is there a utility to get the fan speed on a GeForce card?
    By Paul Adams in forum Graphics Cards
    Replies: 2
    Last Post: 06-12-2003, 05:29 PM
  3. Kill your speed, cut your premium?
    By XTR in forum Automotive
    Replies: 6
    Last Post: 08-11-2003, 02:21 AM
  4. More speed... (upgrade q?)
    By joshwa in forum PC Hardware and Components
    Replies: 6
    Last Post: 29-07-2003, 01:14 AM
  5. athlon XP 2800+ barton stock speed?
    By Spud1 in forum PC Hardware and Components
    Replies: 14
    Last Post: 27-07-2003, 07:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •