Advertisement
Guest User

Redundant Object.ToString

a guest
Dec 12th, 2013
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Redundant_Object.ToString
  8. {
  9.     class Program
  10.     {
  11.  
  12.         static void Main(string[] args)
  13.         {
  14.             doTest();
  15.             Console.ReadLine();
  16.         }
  17.  
  18.         private static async void doTest()
  19.         {
  20.             TimeSpan test1 = new TimeSpan();
  21.             TimeSpan test2 = new TimeSpan();
  22.             TimeSpan test3 = new TimeSpan();
  23.             TimeSpan test4 = new TimeSpan();
  24.  
  25.             for (int x = 0; x < 100; x++)
  26.             {
  27.  
  28.                 test1 += await Task.Factory.StartNew<TimeSpan>(() =>
  29.                             {
  30.                                 Stopwatch sw = new Stopwatch();
  31.                                 sw.Start();
  32.  
  33.                                 MakeKeyToString(1, "Ashley", "MyBrand");
  34.  
  35.                                 sw.Stop();
  36.                                 return sw.Elapsed;
  37.                             });
  38.             }
  39.  
  40.            
  41.  
  42.             for (int x = 0; x < 100; x++)
  43.             {
  44.  
  45.                 test2 += await Task.Factory.StartNew<TimeSpan>(() =>
  46.                 {
  47.                     Stopwatch sw = new Stopwatch();
  48.                     sw.Start();
  49.  
  50.                     MakeKey(1, "Ashley", "MyBrand");
  51.  
  52.                     sw.Stop();
  53.                     return sw.Elapsed;
  54.                 });
  55.             }
  56.  
  57.             for (int x = 0; x < 100; x++)
  58.             {
  59.  
  60.                 test3 += await Task.Factory.StartNew<TimeSpan>(() =>
  61.                 {
  62.                     Stopwatch sw = new Stopwatch();
  63.                     sw.Start();
  64.  
  65.                     NullMakeKeyToString(1, "Ashley", "MyBrand");
  66.  
  67.                     sw.Stop();
  68.                     return sw.Elapsed;
  69.                 });
  70.             }
  71.  
  72.             for (int x = 0; x < 100; x++)
  73.             {
  74.  
  75.                 test4 += await Task.Factory.StartNew<TimeSpan>(() =>
  76.                 {
  77.                     Stopwatch sw = new Stopwatch();
  78.                     sw.Start();
  79.  
  80.                     NullMakeKey(1, "Ashley", "MyBrand");
  81.  
  82.                     sw.Stop();
  83.                     return sw.Elapsed;
  84.                 });
  85.             }
  86.  
  87.             Console.WriteLine("With ToString: " + test1.TotalMilliseconds / 100);
  88.             Console.WriteLine("Without ToString: " + test2.TotalMilliseconds / 100);
  89.             Console.WriteLine("Nullable int With ToString: " + test3.TotalMilliseconds / 100);
  90.             Console.WriteLine("Nullable int Without ToString: " + test4.TotalMilliseconds / 100);
  91.         }
  92.  
  93.         private static string MakeKeyToString(int SnapshotID, string UserName, string BrandName)
  94.         {
  95.             return string.Format("{0}:{1}:{2}", SnapshotID.ToString(), UserName, BrandName);
  96.         }
  97.  
  98.         private static string MakeKey(int SnapshotID, string UserName, string BrandName)
  99.         {
  100.             return string.Format("{0}:{1}:{2}", SnapshotID, UserName, BrandName);
  101.         }
  102.  
  103.         private static string NullMakeKeyToString(int? SnapshotID, string UserName, string BrandName)
  104.         {
  105.             return string.Format("{0}:{1}:{2}", SnapshotID.ToString(), UserName, BrandName);
  106.         }
  107.  
  108.         private static string NullMakeKey(int? SnapshotID, string UserName, string BrandName)
  109.         {
  110.             return string.Format("{0}:{1}:{2}", SnapshotID, UserName, BrandName);
  111.         }
  112.  
  113.     }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement