0

I'm trying to figure out how to find how much time is my application running, but all I can find are:

Clock()
timersub()

and some similar stuff, but I can't use them, ....

what must I include in my code so I can use them?

like I include:

using System.Collections.Generic;

so I can use:

List<int> ints = new List<int>();

and if I do:

#include <time.h> // I get: Wrong preprocessor directive

Also I need floating point since start up and what I do get from:

System.DateTime.Now; // - not float but sealed struct
MilitaryG
  • 75
  • 1
  • 9
  • Have You Tried `Stopwatch` its good for keep tracking of time – Yaser Jaradeh Mar 13 '14 at 15:10
  • "Also I need floating point since start up" - this doesn't really mean much. Do you want the time since the application start up? Or since the device start up? Or the activity start up? And why do you need it in some floating point format? – Jon Skeet Mar 13 '14 at 15:11
  • Note: `#include ` isn't C#. `System.DateTime.Now.Ticks` isn't good? `n / 10000000M` would give you fractions of a second. (note, value only updates every `20ms` or so on most systems) –  Mar 13 '14 at 15:12

2 Answers2

1

I normally use the StopWatch class

using System.Diagnostics;

Stopwatch sw = Stopwatch.StartNew();

Do Stuff...

sw.Stop();
TimeSpan elapsedTime = sw.Elapsed;
0

Normally if you want to time an operation you would use the StopWatch class.

It is available in Mono as well and should work just fine on Linux.

Rune Grimstad
  • 35,612
  • 10
  • 61
  • 76