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