Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello everyone, how can I use the System.Environment, I need this class to calculate the time spent by an algorithm in my project, if anyone know it, please, need your help, thanks and excuse me for my language...
Posted
Comments
Ravi Bhavnani 16-Sep-14 12:17pm    
Why are you asking the same question again? Did you not see the replies to your original question?

http://www.codeproject.com/Answers/819140/How-Can-I-Know-Memory-Consumption-In-My-Project?arn=0#answer1

/ravi

Quote:
I need this class to calculate the time spent by an algorithm in my project
Sure? I would use the StopWatch class[^] for such purpose.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 16-Sep-14 16:21pm    
5ed.
—SA
CPallini 16-Sep-14 16:28pm    
Thank you.
If you just want to calculate the time elapsed by a process, then why are you using Environment when you're having a Stopwatch in the .NET Framework?

http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch(v=vs.110).aspx[^]

You can use the above class, to measure the time elapsed using .NET Framework.

C#
using System;
using System.Diagnostics;
using System.Threading;
class Program
{
    static void Main(string[] args)
    {
        Stopwatch stopWatch = new Stopwatch();
        stopWatch.Start();
        Thread.Sleep(10000);
        stopWatch.Stop();
        // Get the elapsed time as a TimeSpan value.
        TimeSpan ts = stopWatch.Elapsed;

        // Format and display the TimeSpan value. 
        string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
            ts.Hours, ts.Minutes, ts.Seconds,
            ts.Milliseconds / 10);
        Console.WriteLine("RunTime " + elapsedTime);
    }
}


Above code was captured from the link provided.

Using the above code, you can easily set the time and determine the time that had elapsed for that algorithm in your program.
 
Share this answer
 
v2
Comments
ZurdoDev 16-Sep-14 13:48pm    
+5.
Afzaal Ahmad Zeeshan 16-Sep-14 13:50pm    
Thanks! ^_^
Sergey Alexandrovich Kryukov 16-Sep-14 16:21pm    
5ed.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900