I tried it mostly your way and it took 39 seconds. Granted, I don't know the contents of your Stopwatch class, but all mine does is return a
TimeSpan
when I call my
ElapsedTime
method. I'm also making only one call to
Console.Writeline
with a
string.Concat
endated value.
public class StopWatch
{
public DateTime StartTime { get; set; }
public void Start()
{
this.StartTime = DateTime.Now;
}
public TimeSpan ElapsedTime()
{
return (DateTime.Now - this.StartTime);
}
}
static void Main(string[] args)
{
string str = Console.ReadLine();
if (str == "start")
{
StopWatch sw = new StopWatch();
sw.Start();
for (int i = 1; i < 200000; i++)
{
Console.WriteLine(string.Concat("Acccessed Value: ", i.ToString(), ", Time: ", sw.ElapsedTime().ToString()));
}
}
Console.Read();
}