Linked by Christopher W. Cowell-Shah on Thu 8th Jan 2004 19:33 UTC
General Development This article discusses a small-scale benchmark test run on nine modern computer languages or variants: Java 1.3.1, Java 1.4.2, C compiled with gcc 3.3.1, Python 2.3.2, Python compiled with Psyco 1.1.1, and the four languages supported by Microsoft's Visual Studio .NET 2003 development environment: Visual Basic, Visual C#, Visual C++, and Visual J#. The benchmark tests arithmetic and trigonometric functions using a variety of data types, and also tests simple file I/O. All tests took place on a Pentium 4-based computer running Windows XP. Update: Delphi version of the benchmark here.
Permalink for comment
To read all comments associated with this story, please click here.
blah...
by Anonymous on Fri 9th Jan 2004 13:25 UTC

#include "time.h"
#include <iostream>

using namespace std;

template <class T> T arithmetic(const T min, const T max, double& rtime);

int main()
{
const int int_min = 1;
const int int_max = 1000000000; // 1B
const double double_min = 10000000000.0; // 10B
const double double_max = 11000000000.0; // 11B
const long long ll_min = 10000000000; // 10B
const long long ll_max = 11000000000; // 11B

cout << "start c++ benchmark" << endl;

double time;

arithmetic(int_min, int_max, time);
cout << "int arithmetic elapsed time: " << time << " ms. min=" << int_min
<< ",max=" << int_max << endl;

arithmetic(double_min, double_max, time);
cout << "double arithmetic elapsed time: " << time << " ms. min=" << double_min
<< ",max=" << double_max << endl;

arithmetic(ll_min, ll_max, time);
cout << "long long arithmetic elapsed time: " << time << " ms. min=" << ll_min
<< ",max=" << ll_max << endl;

cout << "stop c++ benchmark" << endl;

return 0;
}

class auto_clock
{
clock_t t0;
double& r;
public:
auto_clock(double& rtime)
: r(rtime)
{
t0 = clock();
if (t0 < 0) throw;
}

~auto_clock()
{
clock_t t1 = clock();
if (t1 < 0) throw;
r = (t1 - t0) * 1000.0 / CLOCKS_PER_SEC;
}
};

template <class T> T arithmetic(const T min, const T max, double& rtime)
{
auto_clock ac(rtime);

T r = 1;
T i = min;

while (i < max) {
r -= i++;
r += i++;
r *= i++;
r /= i++;
}

return r;
}