Results 1 to 10 of 21

Thread: [SOLVED] Why is C slower than Java?

Threaded View

  1. #1
    Join Date
    Nov 2012
    Beans
    23

    [SOLVED] Why is C slower than Java?

    I was always told how C is faster than Java, so I decided to write a few very basic programs to see how much slower it is (if at all) at using basic commands like if, for etc. I compiled my code, and Java was significantly faster (although, as always takes longer to compile). Does Java have some sort of extra stuff built into its for loop so that it can do this more efficiently or something?

    Here's my code...

    Code:
    public class speed {
        public static void main(String[] args) {
             int count;
             for( count = 0; count <= 1000000000; count++ ) {
    
             }
             System.out.print( "\n" +count+ "\n" );
         }
    }
    and for C...
    Code:
    #include <stdio.h>
    
    int main(void)
    {
             int count;
             for( count = 0; count <= 1000000000; count++ ) {
        
             }
             printf( "\n%d\n" ,count );
    
             return 0;
    }
    Also, does anyone know how to indent your code here? (Since I tried, but it ignores the spaces at the start of each line when you post).

    Cheers.
    Last edited by usernamer; March 9th, 2013 at 12:17 AM. Reason: Indent code

Tags for this Thread

Bookmarks

Posting Permissions

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