// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; namespace E { public class MainClass { private const int N = 200000000; private const int REP = 3; public static void Main(string[] args) { string s = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; char[] c = s.ToCharArray(); for(int j = 0; j < REP; j++) { DateTime t1 = DateTime.Now; for(int i = 0; i < N; i++) { if(s[i%s.Length] != 'A') throw new Exception("Oops"); } DateTime t2 = DateTime.Now; Console.WriteLine("String : " + (t2 - t1).TotalSeconds); DateTime t3 = DateTime.Now; for(int i = 0; i < N; i++) { if(c[i%s.Length] != 'A') throw new Exception("Oops"); } DateTime t4 = DateTime.Now; Console.WriteLine("Char Array : " + (t4 - t3).TotalSeconds); } } } }