Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Test() {
- System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch ();
- int repetitions = 1000000;
- int subreps = 10;
- List<int> list = new List<int> ();
- for (int i = 0; i < repetitions; i++) { // populate list
- list.Add (0);
- }
- sw.Start ();
- for (int i = 0; i < repetitions; i++) {
- for (int j = 0; j < subreps; j++) {
- int x = list [i];
- }
- }
- print("for loop: " + sw.ElapsedMilliseconds + "ms");
- sw.Reset ();
- sw.Start ();
- foreach (int i in list) {
- for (int j = 0; j < subreps; j++) {
- int x = i;
- }
- }
- print("foreach loop: " + sw.ElapsedMilliseconds + "ms")
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement