Skip to content

Instantly share code, notes, and snippets.

@TWolverson
Created June 8, 2013 11:50
Show Gist options
  • Save TWolverson/5734931 to your computer and use it in GitHub Desktop.
Save TWolverson/5734931 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int[,,] ints = new int[100,100,100];
int count = 0;
var stopwatch = new Stopwatch();
stopwatch.Start();
for (int i = 0; i < 100; i++)
{
for (int j = 0; j < 100; j++)
{
for (int k = 0; k < 100; k++)
{
count += ints[i,j,k];
}
}
}
stopwatch.Stop();
Console.WriteLine(string.Format("Looping took {0} ticks.", stopwatch.ElapsedTicks));
stopwatch.Reset();
stopwatch.Start();
foreach (var i in ints)
{
count += i;
}
stopwatch.Stop();
Console.WriteLine(string.Format("Iterating took {0} ticks.", stopwatch.ElapsedTicks));
Console.Read();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment