Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Odd results with C++ under WinXP SP2

Reply
Thread Tools

Odd results with C++ under WinXP SP2

 
 
Anonymous
Guest
Posts: n/a
 
      02-24-2005
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


 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      02-24-2005
"Anonymous" <(E-Mail Removed)> 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


 
Reply With Quote
 
 
 
 
Donovan Rebbechi
Guest
Posts: n/a
 
      02-24-2005
On 2005-02-24, Anonymous <(E-Mail Removed)> 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/
 
Reply With Quote
 
Llewelly
Guest
Posts: n/a
 
      02-24-2005
"Anonymous" <(E-Mail Removed)> 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]
 
Reply With Quote
 
Ioannis Vranos
Guest
Posts: n/a
 
      02-24-2005
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[i]= array.size()-i;

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


Again use the provided command line options.



--
Ioannis Vranos

http://www23.brinkster.com/noicys
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
A router running under WinXP runs under Windows Vista too? Peter Wagner Wireless Networking 12 02-04-2008 11:02 PM
Slipstreaming winxp 64 sp2 into Winxp 64 Kue2 Windows 64bit 10 03-17-2007 12:13 AM
Odd behavior with odd code Michael Speer C Programming 33 02-18-2007 07:31 AM
Odd Start menu glitch in XP SP2 TrentSC Computer Support 2 02-08-2007 02:48 PM
Calendars overlap : IE SP2 ; WinXP SP2 Likhith Areekkal ASP .Net Web Services 0 12-23-2004 02:58 AM



Advertisments