A
Anonymous
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
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