Skip to content

Instantly share code, notes, and snippets.

@JonRurka
Last active November 3, 2015 21:13
Show Gist options
  • Save JonRurka/88b09228922727e85554 to your computer and use it in GitHub Desktop.
Save JonRurka/88b09228922727e85554 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
namespace loopBenchmark
{
class Program
{
static void Main(string[] args)
{
Stopwatch watch = new Stopwatch();
watch.Start();
for (int i = 0; i < 10000; i++) ;
watch.Stop();
Console.WriteLine("for: " + watch.Elapsed.ToString());
int[] intList = new int[10000];
watch.Start();
foreach (int i in intList) ;
watch.Stop();
Console.WriteLine("foreach: " + watch.Elapsed.ToString());
Console.ReadKey();
}
}
}
output:
for: 00:00:00.0000373
foreach: 00:00:00.0000565
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment