Created
June 8, 2013 11:50
-
-
Save TWolverson/5734931 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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