One of the funny things about computer technology is the bitter industry rivalries that inevitably crop up. There is probably no industry rivalry more bitter or hate-filled than that of .NET and Java.
While it is difficult to quantify definitively which platform is more flexible, easier to use, or easier to learn – we can certainly compare speed. So, havn’t you always wondered – who’s faster: .NET or Java?
Last week, Microsoft released .NET 2.0, the long-awaited major-upgrade to .NET 1.1 – coinciding with the releases of Visual Studio 2005 and SQL Server 2005. Armed with this new software, we set out to determine which is faster - .NET 2.0 or Java 1.5.
Test 1 – Selection Sort
Our first test will utilize the age-old textbook problem of computer sorting algorithms. To thoroughly stress-test the two technology platforms, we chose a highly inefficient sorting algorithm – selection sort. Selection sort is a method of sorting a list of items, typically numeric in nature, from say highest to lowest. Because Java and C# are quite similar we were able to use the same selection sort code with extremely minor modification in Java and C#.
Selection sort is considered to be an inefficient sorting algorithm because its complexity in computer science terms is order n2. This means that if you want to sort a list of 1,000 numbers it will take as many as 1,000,000 steps. We chose selection sort because of its easy portability between C# and Java and – precisely because of its inefficiency and corresponding heavy use of memory – it will help to highlight any performance differences the two platforms.
The following system was used as a testbed:
Pentium D 3.0 Ghz, 2 MB Cache
2 GB DDR2
Windows XP Professional SP2 (Latest Patches, x32)
Hard Disk (Not Important)
2x 250 GB 7200 RPM
So – you must be anxious to see the results. Below is shown the running time in milliseconds of an ascending selection sort on a set of 1,000 descending floating point (double) numbers (the same data was used for .NET and Java). Since this is running time, obviously less time is better.
Selection Sort on 1,000 Floating Point Elements, Time in MS
Now comes the interesting step – let’s scale the dataset up to 100,000 elements, pushing the complexity up to 10,000,000,000 steps:
Selection Sort on 100,000 Floating Point Elements, Time in MS
It looks like Test 1 has a clear winner - .NET 2.0. Interestingly, the same general proportions between completion times for the two platforms remains similar – hence the same proportions portrayed in the graphs, despite the drastic increase in input size. In the larger test, Java required 36,828 ms to complete the job, while .NET took 21,375 ms; .NET required only 58% of the time required by Java to complete the same task. That’s nearly 2-to-1.