1: SecureString secString = new SecureString();
2:
3: String str=String.Empty;
4: Stopwatch sw = new Stopwatch();
5:
6: Int32 loopCounter = 0;
7: Int32 loopMaxCounter = 10000;
8: Console.WriteLine("---------------------------------------------------------");
9: Console.WriteLine("Loop will run {0} times",loopMaxCounter);
10: Console.WriteLine("Current String Length is {0}", str.Length.ToString());
11: sw.Start();
12: for (loopCounter = 0; loopCounter < loopMaxCounter; loopCounter++)
13: {
14: str = str + "a";
15: }
16: Console.WriteLine("String insertion completed in {0} milliseconds",sw.Elapsed.Milliseconds.ToString());
17: Console.WriteLine("Current length of String is {0}.", str.Length.ToString());
18: Console.WriteLine("----------------------------------------------------------");
19: sw.Stop();
20: sw.Reset();
21: sw.Start();
22: Console.WriteLine("----------------------------------------------------------");
23: Console.WriteLine("Loop will run {0} times", loopMaxCounter);
24: Console.WriteLine("Current Secure String Length is {0}", str.Length.ToString());
25: for (loopCounter = 0; loopCounter < loopMaxCounter; loopCounter++)
26: {
27: try
28: {
29: secString.AppendChar('a');
30: }
31: catch (Exception ex)
32: {
33: Console.WriteLine(ex.ToString());
34: }
35: }
36: Console.WriteLine("Secure String insertion completed in {0} milliseconds", sw.Elapsed.Milliseconds.ToString());
37: Console.WriteLine("Current length of Secure String is {0}.", secString.Length.ToString());
38: Console.WriteLine("-----------------------------------------------------------");
39: sw.Stop();
40: Console.Read();