2.3. C# Performance

Java programmers know about Java's performance issues, so at this point it is only fair to quickly glance at C#'s performance.

A good test of a language's performance is to see how long it takes the two languages to iterate over a for loop 10 million times. Listing 2.13 shows the C# code, and Listing 2.14 shows the corresponding Java code. Note that in C# Environment.TickCount returns the time elapsed in milliseconds since the system started. This is a close equivalent of Java's System .currentTimeMillis() function.

Listing 2.13. Iterating 10 Million Times (C#)
 1 using System; 2 public class ForLoopTest { 3 public static void Main(string[] args) { 4 long start = Environment.TickCount; 5 for (int i =0;i < 10000000; ++i) { ...

Get .NET for Java Developers: Migrating to C# now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.