Computational Performance Benchmarks

I was curious about the performance of the new .NET languages, so I threw together a simple benchmark for computation: computing pi to an arbitrary number of digits. I took the same program and implemented it in several different languages. Each time, I did my best to express the program in the idioms and style appropriate to the language, while also trying to achieve the best performance for that language.

The algorithm is not the fastest way to computer pi (n2 where n in the number of digits), but it is easy to code and doesn't require a lot of memory. (Rabinowitz, S. and Wagon, S., A spigot algorithm for the digits of pi, American Mathematical Monthly, 102(3), March 1995, pp. 195-203.)

All the source code is available here, including the simple timer program that I used (which is written in Delphi):

Source code: Delphi      C      C++      C#      Java      Perl      Python      Timer (Delphi)

I used the following tools to compile or run the programs:

Borland Delphi 6 Update 2

Borland C++ Builder 6

Metrowerks CodeWarrior 6

Microsoft Visual Studio .NET

ActiveState Perl 5.6.1

Python 2.2

I ran the Java.class file using two different JVMs: Microsoft jview 5.00.3802 and JDK 1.3.1 HotSpot Client VM.

You must install .NET framework to run the Visual C# executable. All the other executables are self-contained. The .class file depends only on standard Java packages. You need a Perl implementation to run the Perl program (any current version should do.) You need Python to run the Python program.

Compiled executables: Delphi  Borland C    Borland C++   Metrowerks C    Metrowerks C++   Visual C    Visual C++    Visual C#    Java class

Python and Perl (the interpreted languages) perform significantly worse than everything else, and Python is much worse than Perl.

Taking out Python and Perl, we can see the other languages. Java has the worst performance and C (vendor 2) has the best. Vendor 2 has the best C and C++ compilers, followed by vendor 1. Vendor 3 has the worst: its C and C++ compilers fared similarly to Java and the proprietary languages.

The licenses for Visual Studio .NET, Borland C++ Builder, and Borland Delphi prohibit me from publishing benchmark results, so you will have to figure out which program is which on your own.

Below are the raw numbers. All tests were performed on a Pentium III/600, in a VMware 3.0 virtual machine, running Windows NT 4 SP 6a, with 192MB RAM. (The host system is Linux, kernel 2.4.16 with 512MB RAM.)
  seconds
# Digits Lang 1 C 1 C++ 1 C 2 C++ 2 C 3 C++ 3 Lang 2 jview JDK 1.3.1 Perl Python

5

0.261

0.120

0.201

0.100

0.120

0.080

0.100

0.350

0.421

1.523

0.190

0.240

10

0.210

0.121

0.160

0.090

0.110

0.141

0.110

0.341

0.280

0.961

0.100

0.231

50

0.180

0.120

0.140

0.091

0.120

0.090

0.100

0.250

0.311

1.041

0.121

0.270

100

0.150

0.140

0.140

0.090

0.120

0.110

0.101

0.271

0.270

0.742

0.200

0.421

500

0.271

0.220

0.241

0.170

0.191

0.200

0.230

0.410

0.371

0.861

3.044

5.488

1000

0.641

0.501

0.551

0.410

0.480

0.551

0.621

0.751

0.761

1.292

11.937

21.180

5000

12.388

8.983

9.113

7.682

8.242

11.386

12.518

13.009

12.919

14.270

300.012

531.314

10000

49.050

37.314

36.783

30.854

33.068

46.157

50.923

51.765

51.634

54.849

1198.984

2141.770

15000

113.053

87.586

84.701

72.264

77.481

109.397

119.932

118.049

117.459

124.559

2723.847

4829.094

20000

205.245

160.290

156.235

132.240

141.103

200.879

220.447

210.803

211.364

224.293

4795.175

8589.501