Java vs C++ speed (IO & Sorting) - Java

This is a discussion on Java vs C++ speed (IO & Sorting) - Java ; On Thu, 20 Mar 2008 04:12:33 -0700 (PDT), James Kanze <james.kanze@gmail.com> wrote: >Who ever claimed a speed advantage for C++? You were here 7 years ago ... I remember your name. Are you claiming no one has ever said c++ ...

+ Reply to Thread
Page 3 of 54 FirstFirst 1 2 3 4 5 13 53 ... LastLast
Results 21 to 30 of 536

Java vs C++ speed (IO & Sorting)

  1. Default Re: Java vs C++ speed (IO & Sorting)

    On Thu, 20 Mar 2008 04:12:33 -0700 (PDT), James Kanze
    <james.kanze@gmail.com> wrote:

    >Who ever claimed a speed advantage for C++?



    You were here 7 years ago ... I remember your name. Are you claiming
    no one has ever said c++ has huge speed advantage? If that's your
    claim, then you are either being dishonest or have a bad memory





  2. Default Re: Java vs C++ speed (IO & Sorting)

    Razii wrote:
    > On Thu, 20 Mar 2008 10:36:20 +0000 (UTC), Lionel B <me@privacy.net>
    > wrote:
    >
    >> That's probably why he suggested using `multiset'.

    >
    > By the way, have look at 2001 post where I used set...
    >
    > http://groups.google.com/group/comp....5ebf877e25b287
    >
    > In that case, it didn't make a difference because bible.txt I was
    > using had verse numbers (so there could be no duplicates). A few here
    > (including Pete Becker from dinkumware) claimed that I used set and it
    > was unfair...
    >
    > In any case, I can use multiset...
    >
    > Time for reading, sorting, writing: 328 ms (c++)
    > Time for reading, sorting, writing: 312 ms (c++)
    > Time for reading, sorting, writing: 312 ms (c++)
    >
    > Just a little improvement only...
    >

    So you have a slow system that may be I/O bound, or you have a poor
    multiset implementation. Try checking the read and write times on your
    original code.

    --
    Ian Collins.

  3. Default Re: Java vs C++ speed (IO & Sorting)

    In article <eue4u3dnkbif9tvvesvlf3qdjiga6f8l47@4ax.com>,
    Razii <DONTwhatevere3e@hotmail.com> wrote:
    >
    >Yawn. I really care what language you use (NOT).


    If you don't care about what language other peoples use, why are
    trying to start a flame war across 2 newsgroup?





  4. Default Re: Java vs C++ speed (IO & Sorting)

    On Thu, 20 Mar 2008 12:45:49 +0200, Juha Nieminen
    <nospam@thanks.invalid> wrote:

    > 1) 300 ms is too short of a time for any reliable comparison.



    I made bible.txt 10 times and made it a 43 meg file

    C++ is doing far worse now (the code used was multiset version)

    Time for reading, sorting, writing: 2047 ms (java)
    Time for reading, sorting, writing: 2016 ms (java)
    Time for reading, sorting, writing: 2016 ms (java)
    Time for reading, sorting, writing: 2015 ms (java)


    and for c++

    Time for reading, sorting, writing: 5281 ms (c++)
    Time for reading, sorting, writing: 5703 ms (c++)
    Time for reading, sorting, writing: 3921 ms (c++)
    Time for reading, sorting, writing: 3718 ms (c++)

    How come? c++ is at least 45% times slowe (if using 3718 ms)


  5. Default Re: Java vs C++ speed (IO & Sorting)

    On Fri, 21 Mar 2008 00:39:22 +1300, Ian Collins <ian-news@hotmail.com>
    wrote:

    >So you have a slow system that may be I/O bound, or you have a poor
    >multiset implementation. Try checking the read and write times on your
    >original code.


    Well, the java code is running on the same "slow system"

    And see the other post .. make bible.txt 10 times bigger by copying
    and pasting 9 more times. Make it 43 meg file. After that,...

    Time for reading, sorting, writing: 2047 ms (java)
    Time for reading, sorting, writing: 2016 ms (java)
    Time for reading, sorting, writing: 2016 ms (java)
    Time for reading, sorting, writing: 2015 ms (java)


    and for c++

    Time for reading, sorting, writing: 5281 ms (c++)
    Time for reading, sorting, writing: 5703 ms (c++)
    Time for reading, sorting, writing: 3921 ms (c++)
    Time for reading, sorting, writing: 3718 ms (c++)

    c++ performed even worse...


  6. Default Re: Java vs C++ speed (IO & Sorting)

    On 20 Mar 2008 11:50:11 GMT, ytrembla@nyx.nyx.net (Yannick Tremblay)
    wrote:

    >If you don't care about what language other peoples use, why are
    >trying to start a flame war across 2 newsgroup?


    It's not a flame war. It's a discussion and testing. If you are not
    interesting in it, just move on to next thread.

  7. Default Re: Java vs C++ speed (IO & Sorting)

    On Thu, 20 Mar 2008 06:55:27 -0500, Razii
    <DONTwhatevere3e@hotmail.com> wrote:

    >c++ performed even worse...


    k, I figure out the reason .. there are no duplicates in TreeSet in
    Java

  8. Default Re: Java vs C++ speed (IO & Sorting)

    On 20 Mar., 11:46, Razii <DONTwhatever...@hotmail.com> wrote:
    > On Thu, 20 Mar 2008 03:01:28 -0700 (PDT), peter koch
    >
    > <peter.koch.lar...@gmail.com> wrote:
    > >I also
    > >notice that the time included does not involve releasing memory used
    > >by the Java-program which is unfair as this time was measured in the C+
    > >+ version.

    >
    > You are not making sense. Where on earth is c+ releasing memory in the
    > code that I posted?
    >
    > >Be that as it is, I notice that the C++ version is fifty percent
    > >shorter which suggests that developing with C++ will be quite a lot
    > >faster.

    >
    > No, it's generally accepted that developing in C++ is much slower and
    > difficult due to pathetic c++ library, no thread support, no network
    > library.


    This is weird. If the C++ library is so bad I do not understand why
    the C++ code in your example is so much clearer than the Java
    equivalent with an "endless" loop that is exited in the middle.
    Apart from that, the C++ philosophy is very different from the Java
    one: Java has an "everything in one package" whereas in C++ you
    typically use add-on packages. So if you use threading and networking,
    just use e.g. Posix or Corba or boost which gives you everything.

    As for the length of code I posted, I can jumble everything
    > together and make Java code look short
    >
    > import java.io.*;  import java.util.*;  public class IOSort
    > {public static void main(String[] arg) throws Exception {
    > ArrayList<String> ar = new ArrayList<String>(50000); String line = "";
    > BufferedReader in = new BufferedReader( new FileReader("bible.txt"));
    > PrintWriter out  = new PrintWriter(new BufferedWriter(new
    > FileWriter("output.txt"))); long start = System.currentTimeMillis();
    > while (true) { line = in.readLine(); if (line == null) break;
    > ar.add(line);  } Collections.sort(ar); int size = ar.size();
    > for (int i = 0; i < size; i++) { out.println(ar.get(i));}
    > out.close();  long end = System.currentTimeMillis();
    > System.out.println("Time for reading, sorting, writing: "+ (end -
    > start) + " ms"); } }
    >
    > I hope you are satisfied )


    Right. But count the number of statements: they are the same. And
    still the same half time longer.
    >
    > On a serious note, I also removed an unneeded line, (if (line.length()
    > ==0)  continue that was in the loop. That probably helped in speed..


    It did? That would give you more lines to sort, wouldn't it?

    >
    > >So all in all, the above benchmark could never make me consider
    > >switching languages.

    >
    > Yawn. I really care what language you use (NOT).


    I do not know your purpose of that test, but to me it confirms that
    you should use C++ and not Java. I guess that must be of relevance
    somewhere?

    /Peter

  9. Default Re: Java vs C++ speed (IO & Sorting)

    On Mar 20, 4:28 am, Razii <DONTwhatever...@hotmail.com> wrote:
    > On Thu, 20 Mar 2008 04:12:33 -0700 (PDT), James Kanze
    >
    > <james.ka...@gmail.com> wrote:
    > >Who ever claimed a speed advantage for C++?

    >
    > You were here 7 years ago ... I remember your name. Are you claiming
    > no one has ever said c++ has huge speed advantage? If that's your
    > claim, then you are either being dishonest or have a bad memory


    This specific test has a lot of room to be specialized. A quick
    example: arenas and intrusive containers. Near zero-overhead paged
    allocation means less memory usage and much faster execution, and
    boost.intrusive's multiset container can give less overhead than a
    std::multiset and better locality.

    Is such optimization usually needed? No. But after you've profiled
    if you decide your approach isn't adequate, C++ gives you a lot more
    freedom than Java to do so when you need it. Apples to apples
    comparisons are silly: in what real-world situation would you limit
    your app design because another language can't do something?

    And I question both benchmarks' timing methods. On Windows, clock()
    will return wall time. On *nix it will return real processor usage
    time. These should both be measuring processor usage, not wall time.

  10. Default Re: Java vs C++ speed (IO & Sorting)

    On Thu, 20 Mar 2008 01:10:17 -0500, Razii <fdgldfj@hotmails.com>
    wrote, quoted or indirectly quoted someone who said :

    >------------------- Java Code -------------- (same as 7 years ago


    Unfair. C++ gets the benefit of a static optimisation. Let Java have
    one too. see http://mindprod.com/jgloss/jet.html
    --

    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com

+ Reply to Thread
Page 3 of 54 FirstFirst 1 2 3 4 5 13 53 ... LastLast