Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Threading.Tasks;
- namespace Redundant_Object.ToString
- {
- class Program
- {
- static void Main(string[] args)
- {
- doTest();
- Console.ReadLine();
- }
- private static async void doTest()
- {
- TimeSpan test1 = new TimeSpan();
- TimeSpan test2 = new TimeSpan();
- TimeSpan test3 = new TimeSpan();
- TimeSpan test4 = new TimeSpan();
- for (int x = 0; x < 100; x++)
- {
- test1 += await Task.Factory.StartNew<TimeSpan>(() =>
- {
- Stopwatch sw = new Stopwatch();
- sw.Start();
- MakeKeyToString(1, "Ashley", "MyBrand");
- sw.Stop();
- return sw.Elapsed;
- });
- }
- for (int x = 0; x < 100; x++)
- {
- test2 += await Task.Factory.StartNew<TimeSpan>(() =>
- {
- Stopwatch sw = new Stopwatch();
- sw.Start();
- MakeKey(1, "Ashley", "MyBrand");
- sw.Stop();
- return sw.Elapsed;
- });
- }
- for (int x = 0; x < 100; x++)
- {
- test3 += await Task.Factory.StartNew<TimeSpan>(() =>
- {
- Stopwatch sw = new Stopwatch();
- sw.Start();
- NullMakeKeyToString(1, "Ashley", "MyBrand");
- sw.Stop();
- return sw.Elapsed;
- });
- }
- for (int x = 0; x < 100; x++)
- {
- test4 += await Task.Factory.StartNew<TimeSpan>(() =>
- {
- Stopwatch sw = new Stopwatch();
- sw.Start();
- NullMakeKey(1, "Ashley", "MyBrand");
- sw.Stop();
- return sw.Elapsed;
- });
- }
- Console.WriteLine("With ToString: " + test1.TotalMilliseconds / 100);
- Console.WriteLine("Without ToString: " + test2.TotalMilliseconds / 100);
- Console.WriteLine("Nullable int With ToString: " + test3.TotalMilliseconds / 100);
- Console.WriteLine("Nullable int Without ToString: " + test4.TotalMilliseconds / 100);
- }
- private static string MakeKeyToString(int SnapshotID, string UserName, string BrandName)
- {
- return string.Format("{0}:{1}:{2}", SnapshotID.ToString(), UserName, BrandName);
- }
- private static string MakeKey(int SnapshotID, string UserName, string BrandName)
- {
- return string.Format("{0}:{1}:{2}", SnapshotID, UserName, BrandName);
- }
- private static string NullMakeKeyToString(int? SnapshotID, string UserName, string BrandName)
- {
- return string.Format("{0}:{1}:{2}", SnapshotID.ToString(), UserName, BrandName);
- }
- private static string NullMakeKey(int? SnapshotID, string UserName, string BrandName)
- {
- return string.Format("{0}:{1}:{2}", SnapshotID, UserName, BrandName);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement