d-programming-language.org

Benjamin Lindley benjameslindley at gmail.com
Mon Jul 4 18:14:30 PDT 2011


On 7/4/2011 7:38 PM, Mehrdad wrote:
> Actually, there is **NO** performance issue -- at least not in C#. In
> fact, if you run this program (with or without optimizations), you will
> see that they're literally the same almost all the time:
>
> using System;
>
> static class Program
> {
> static long globalVar = 0; //Make it static so it doesn't get optimized
> static void Main()
> {
> const long COUNT = 100000000;
> for (;;)
> {
> var start = Environment.TickCount;
> for (long i = 0; i < COUNT; i++)
> checked { globalVar = i * i; }
> System.Console.WriteLine("Checked: {0}", Environment.TickCount - start);
>
> start = Environment.TickCount;
> for (long i = 0; i < COUNT; i++)
> unchecked { globalVar = i * i; }
> System.Console.WriteLine("Unchecked: {0}", Environment.TickCount - start);
> }
> }
> }
>
> There is literally no performance issue. Ever.
>
>
> Just my 2c

I ran your program, and my results are different than yours.

Checked:   1497
Unchecked: 531
Checked:   1138
Unchecked: 453
Checked:   1092
Unchecked: 468
Checked:   1092
Unchecked: 452
Checked:   1077
Unchecked: 452
Checked:   1108
Unchecked: 452
Checked:   1186
Unchecked: 452
Checked:   1092
Unchecked: 437
Checked:   1092
Unchecked: 452
Checked:   1092
Unchecked: 453
Checked:   1138
Unchecked: 437


More information about the Digitalmars-d mailing list