Home
Browse all 647 examples
Download all 647 examples
Download sample chapters
Reviews
Errata
Acknowledgments
Links on .NET
Paradoxal Press

Buy directly from Paradoxal Press at $33.99 (Save 43%)



Category: Programming
Level: Beginner to seasoned
900 pages
ISBN-10 097661322-0
ISBN-13 978-097661322-0
$59.99 USA
$79.99 CANADA


Listing 15-5 extracted from chapter Collections


Listing 15-4<     > Listing 15-6


This listing can be compiled with the command line:
csc.exe /target:exe Example_15_5.cs
Errors: 0 Warnings: 0


Example_15_5.cs
using System;
using System.Diagnostics;
class Program {
   const int N_ITERATION = 10000;
   const int N_ELEM = 100;
   static void Main() {
      int tmp = 0;

      int[][] arrayJagged = new int[N_ELEM][];
      for (int = 0; i < N_ELEM; i++)
         arrayJagged[i] = new int[N_ELEM];
      Stopwatch sw = Stopwatch.StartNew();
      for (int = 0; k < N_ITERATION; k++)
         for (int = 0; i < N_ELEM; i++)
            for (int = 0; j < N_ELEM; j++){
               tmp = arrayJagged[i][j];
               arrayJagged[i][j] = i * j;
            }
      Console.WriteLine("Jagged array: " + sw.Elapsed );

      int[,] arrayMultiDim = new int[N_ELEM, N_ELEM];
      sw = Stopwatch.StartNew();
      for (int = 0; k < N_ITERATION; k++)
         for (int = 0; i < N_ELEM; i++)
            for (int = 0; j < N_ELEM; j++){
               tmp = arrayMultiDim[i, j];
               arrayMultiDim[i, j] = i * j;
            }
      Console.WriteLine("Multi-dimensional array: " + sw.Elapsed );
   }
}	
Copyright Patrick Smacchia 2006 2007