Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 21

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

  1. #11
    Join Date
    Nov 2012
    Beans
    23

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

    I'm sure it is generally, but with this example of a for loop and printing a number each time within that loop, it doesn't seem to be the case, which surprised me.

  2. #12
    Join Date
    May 2007
    Location
    Leeds, UK
    Beans
    1,675
    Distro
    Ubuntu

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

    I don't suggest this is a flawless benchmark, it's no more than idle amusement ...

    Code:
    $ make benchmark
    time ./eratc
    C
    
    real	0m9.573s
    user	0m9.557s
    sys	0m0.008s
    time ./eratcxx
    C++
    
    real	0m10.580s
    user	0m10.557s
    sys	0m0.012s
    time ./eratp
    Pascal
    
    real	0m11.969s
    user	0m11.941s
    sys	0m0.016s
    time java Erat
    Java
    
    real	0m11.220s
    user	0m11.245s
    sys	0m0.076s
    time ./eratpy.py
    Python (only 1/10 of the iterations)
    
    real	0m36.453s
    user	0m36.350s
    sys	0m0.056s
    
    Note that the Python version only runs 1/10 of the iterations, so you could extrapolate that to ~365s. It can be compiled of course, if anyone wants to try that (or to eliminate the sqrt). Source code attached -- you'll need Free Pascal installed to try the Pascal, or just remove it from the Makefile.

    Comparison.tar.gz
    Please create new threads for new questions.
    Please wrap code in code tags using the '#' button or enter it in your post like this: [code]...[/code].

  3. #13
    Join Date
    Aug 2011
    Location
    47°9′S 126°43W
    Beans
    2,172
    Distro
    Ubuntu 16.04 Xenial Xerus

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

    Quote Originally Posted by MustafaJF View Post
    C is so faster than java
    java is the slowest programming language i have ever wrote program in
    Then you haven't tried many...

  4. #14
    Join Date
    Aug 2011
    Location
    47°9′S 126°43W
    Beans
    2,172
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: Why is C slower than Java?

    Quote Originally Posted by r-senior View Post
    Java usually benchmarks around 110-120% of the execution time of C and C++ for equivalent code.

    I've got some Eratosthenes sieve programs somewhere that are consistent with this. Exact same algorithm in C, C++, Java, Pascal and Python. Still not a perfect benchmark but more realistic than an empty loop. I'll post them later if you want to play with them.
    I have converted a prime factor extraction from C to Java and Java is more like 80% slower than C for this. But then there are different Java runtimes (using IBM JDK 1.6).

  5. #15
    Join Date
    Jan 2012
    Beans
    123
    Distro
    Ubuntu 13.04 Raring Ringtail

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

    Quote Originally Posted by ofnuts View Post
    Then you haven't tried many...
    If "C - C++ - C# - JAVA - Pascal - ASP.net - ASP classic" are not many
    yeah, you are right.

  6. #16
    Join Date
    Feb 2009
    Beans
    1,469

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

    I think ofnuts meant that you really don't have far to look to find a language implementation that underperforms Java (for some applications), so saying it's the slowest thing you've ever used says more about the range of your experience than the limitations of Java itself. (It probably also says something about the kind of programs you write; Java performs better with straight mathematics than heavy text manipulation, for instance.)

    Python and LabVIEW come to mind as fairly popular languages that I've used that may underperform in certain areas when compared to Java.
    Last edited by trent.josephsen; March 9th, 2013 at 06:17 PM.

  7. #17
    Join Date
    Jan 2012
    Beans
    123
    Distro
    Ubuntu 13.04 Raring Ringtail

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

    dear trent.josephsen it dosn`t matter what our frient meant : the java, the program i written in java or ...
    java is slow, maybe not the slowest but it is slower than C - C++ - Python - even C#

  8. #18
    Join Date
    Mar 2010
    Location
    London
    Beans
    924

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

    Quote Originally Posted by MustafaJF View Post
    dear trent.josephsen it dosn`t matter what our frient meant : the java, the program i written in java or ...
    java is slow, maybe not the slowest but it is slower than C - C++ - Python - even C#

    Then perhaps you need to go back and redesign that Java program. I struggle to see how a python implementation of a program is faster than the same program implemented in Java.
    - "Make me a coffee..."
    - "No"
    - "sudo make me a coffee"
    - "OK"

  9. #19
    Join Date
    May 2007
    Location
    Leeds, UK
    Beans
    1,675
    Distro
    Ubuntu

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

    Could you give us a timed example where Python runs faster than an equivalent Java program written with a modern JDK and JVM?
    Please create new threads for new questions.
    Please wrap code in code tags using the '#' button or enter it in your post like this: [code]...[/code].

  10. #20
    Join Date
    Aug 2006
    Location
    60°27'48"N 24°48'18"E
    Beans
    3,458

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

    I honestly would love to get some examples as well. I have written my fair share of number-crunchers and algorithm implementations in my time in all of Java, C and Python, and generally Java is almost always performant enough not to justify implementation in C because of Java's speed of development, while Python likewise tends to choke very quickly indeed...
    LambdaGrok. | #ubuntu-programming on FreeNode

Page 2 of 3 FirstFirst 123 LastLast

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
  •