Odd results with C++ under WinXP SP2

Discussion in 'C++' started by Anonymous, Feb 24, 2005.

  1. Anonymous

    Anonymous Guest

    I have written a series of applications in different languages to compare
    them. In my first one, I am testing console output. On my first test OS
    (Mandrake Linux), C++ came in second, just behind Perl. However, on Windows
    XP, C++ is falling behind badly. I am compiling using the Microsoft Visual
    C++ Toolkit 2003 Compiler, and providing the /O2 option to compile for
    speed. Still, the others are easily doing the task three times as
    effeciently as C++. Perhaps I have made an error (should I be using a
    different compiler? did I make a coding error?). Any advice would be very
    enlightening.

    My test languages are: C++, Java, Perl, Python, & Ruby. On Linux, Perl came
    in ahead of C++, but all others behind. Here is my source code:

    **C++**
    //Raw Console Output - C++ test
    #include <iostream>
    int main() {
    std::cout << "C++ Raw Output Test Commencing...\n\n";
    for(unsigned long i=0; i<200000; i++) {
    std::cout << "Count: " << i << "\n";
    }
    std::cout << "C++ Raw Output Test Complete.\n\n";
    }

    **Java**
    //Raw Console Output - Java test
    public class consoleoutput {
    public static void main(String[] args) {
    System.out.print("Java Raw Output Test Commencing...\n\n");
    for(long i=0; i<200000; i++) {
    System.out.println("Count: " + i);
    }
    System.out.print("Java Raw Output Test Complete.\n\n");
    }
    }


    **Python**
    #!/usr/bin/python
    #Raw Console Output - Python Test
    print 'Python Raw Output Test Commencing...\n'
    i=0
    while i<200000:
    print 'Count: %d' % i
    i=i+1

    (in Python, those spaces actually are tabs in my file)

    I will provide my other source code if required.
    To be precise, C++ is using all of the CPU, and taking 56.48 sec.
    Java is using 46% of the CPU, and taking 36.64 sec.
    Python is using 65% of the CPU, and taking 37 sec.
    I am using Windows XP Home SP2, with 1.8 GHz Pentium 4 Processor, and 256 MB
    RAM.

    --
    Anonymous

    "Treat your password like your toothbrush.
    Don't let anybody else use it, and get
    a new one every six months."
    ---Clifford Stoll
     
    Anonymous, Feb 24, 2005
    #1
    1. Advertising

  2. "Anonymous" <> wrote...
    >I have written a series of applications in different languages to compare
    >them. In my first one, I am testing console output. [...]
    > Perhaps I have made an error (should I be using a different compiler? did
    > I make a coding error?)[..]


    You didn't make a mistake yet, AFAICS. However, you're probably about
    to make one. The mistake will be to derive any conclusion from your
    "comparisons".

    V
     
    Victor Bazarov, Feb 24, 2005
    #2
    1. Advertising

  3. On 2005-02-24, Anonymous <> wrote:
    > I have written a series of applications in different languages to compare
    > them.


    Compare what, the applications or the languages ? If you think you're
    comparing the languages in a meaningful way, there's your first mistake right
    there.

    As far as IO performance is concerned, buffering is an issue -- I remember the
    language shootout page using some obscure buffer that is seldom used outside
    benchmarks (go figure) setting to get the C++ program to perform faster. BTW,
    if you're trying to make the program run as slowly as possible, use std::cin
    as well as std::cout. Otherwise, try doing away with iostreams.

    Most valid C programs are also valid C++, so if the C program beats C++ by a
    wide margin, that tells you that you could have written a faster C++ program.

    Cheers,
    --
    Donovan Rebbechi
    http://pegasus.rutgers.edu/~elflord/
     
    Donovan Rebbechi, Feb 24, 2005
    #3
  4. Anonymous

    Llewelly Guest

    "Anonymous" <> writes:

    > I have written a series of applications in different languages to compare
    > them. In my first one, I am testing console output. On my first test OS
    > (Mandrake Linux), C++ came in second, just behind Perl. However, on Windows
    > XP, C++ is falling behind badly. I am compiling using the Microsoft Visual
    > C++ Toolkit 2003 Compiler, and providing the /O2 option to compile for
    > speed. Still, the others are easily doing the task three times as
    > effeciently as C++. Perhaps I have made an error (should I be using a
    > different compiler? did I make a coding error?). Any advice would be very
    > enlightening.
    >
    > My test languages are: C++, Java, Perl, Python, & Ruby. On Linux, Perl came
    > in ahead of C++, but all others behind. Here is my source code:
    >
    > **C++**
    > //Raw Console Output - C++ test
    > #include <iostream>
    > int main() {
    > std::cout << "C++ Raw Output Test Commencing...\n\n";
    > for(unsigned long i=0; i<200000; i++) {
    > std::cout << "Count: " << i << "\n";


    This isn't raw output at all! In C++, the << operators do _formatted_
    i/o, not raw.

    For raw i/o, you must use a streambuf.

    > }
    > std::cout << "C++ Raw Output Test Complete.\n\n";
    > }

    [snip]
     
    Llewelly, Feb 24, 2005
    #4
  5. Anonymous wrote:

    > I have written a series of applications in different languages to compare
    > them. In my first one, I am testing console output. On my first test OS
    > (Mandrake Linux), C++ came in second, just behind Perl. However, on Windows
    > XP, C++ is falling behind badly. I am compiling using the Microsoft Visual
    > C++ Toolkit 2003 Compiler, and providing the /O2 option to compile for
    > speed. Still, the others are easily doing the task three times as
    > effeciently as C++. Perhaps I have made an error (should I be using a
    > different compiler? did I make a coding error?). Any advice would be very
    > enlightening.
    >
    > My test languages are: C++, Java, Perl, Python, & Ruby. On Linux, Perl came
    > in ahead of C++, but all others behind. Here is my source code:
    >
    > **C++**
    > //Raw Console Output - C++ test
    > #include <iostream>
    > int main() {
    > std::cout << "C++ Raw Output Test Commencing...\n\n";
    > for(unsigned long i=0; i<200000; i++) {
    > std::cout << "Count: " << i << "\n";
    > }
    > std::cout << "C++ Raw Output Test Complete.\n\n";
    > }




    First is the fact that 256 MB are not enough for XP SP2 and it is
    certain that paging file operations occur affecting benchmarks.

    Secondly you should increase the buffer of cout since you are interested
    in console output benchmarks.

    Third you should use the following switches:

    cl /O2 /Og /Oi /Oy /GA /G7 /arch:SSE2 /EHsc temp.cpp


    Finally so as to avoid buffering optimisation issues, a more reliable
    benchmark would be non-console operations like sorting of arrays.


    #include <valarray>
    #include <algorithm>


    int main()
    {
    using namespace std;

    // 20 MB
    const unsigned long SIZE=20*1024*1024;

    valarray<int> array(SIZE);


    for(unsigned long i=0; i<array.size(); ++i)
    array= array.size()-i;

    sort(&array[0], &array[0]+array.size());
    }


    Again use the provided command line options.



    --
    Ioannis Vranos

    http://www23.brinkster.com/noicys
     
    Ioannis Vranos, Feb 24, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter Afonin
    Replies:
    2
    Views:
    322
    Peter Afonin
    Aug 17, 2004
  2. George
    Replies:
    5
    Views:
    784
    =?Utf-8?B?S2VuIEJlYXJk?=
    Aug 24, 2004
  3. DotNetJunkies User

    Access denied to DCOM ASP.net WinXP sp2

    DotNetJunkies User, Oct 8, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    475
    =?Utf-8?B?VWJiZTE3?=
    Oct 11, 2004
  4. =?Utf-8?B?VWJiZTE3?=

    access denied to DCOM, winXP sp2

    =?Utf-8?B?VWJiZTE3?=, Oct 8, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    3,134
    =?Utf-8?B?VWJiZTE3?=
    Oct 14, 2004
  5. Likhith Areekkal

    Calendars overlap : IE SP2 ; WinXP SP2

    Likhith Areekkal, Dec 23, 2004, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    144
    Likhith Areekkal
    Dec 23, 2004
Loading...

Share This Page