# Duration of Algorithm

Hello everyone,

is there an existing function or way to get out the duration of a algorithm in (milli)seconds?

Turn on profiling?

Yes i know, but i wanna show it into my App during Runtime

Don’t do this. Try in seconds. Everything else will make your algorithm much slower.

… in this way?

[h]Pseudocode?[/h]

```Dim start As Integer = Ticks 'Algorithm 'End of Algorithm Dim Total As Double = (Ticks/60/60) - (start/60/60) Return Total ```

That will work. You can also use Microseconds instead of Ticks if you need finer resolution.

Cool Tim Could you give me an example please?

This is one way using seconds

``````Dim startDate as New Date
'Algorithm
'End of Algorithm
Dim endDate as New Date
Return endDate.TotalSeconds - startDate.TotalSeconds``````

[quote=235620:@Albin Kiland]This is one way using seconds

``` Dim startDate as New Date 'Algorithm 'End of Algorithm Dim endDate as New Date Return endDate.TotalSeconds - startDate.TotalSeconds ```[/quote]
Thank you Albin, you are right. So simple

[quote=235615:@Beatrix Willius]See http://documentation.xojo.com/index.php/Ticks .

Don’t do this. Try in seconds. Everything else will make your algorithm much slower.[/quote]

Why is that?
I always debug with:
Dim ms As Double = Microseconds
…blah
System.DebugLog(Str(Microseconds - ms))

Is that expensive?

@Marco Hof: I thought that Martin wanted to see the duration in a progress window while the algorithm was running. And this is expensive.

Ah yes. Using that during the progress is not a good idea.

Using Microseconds to time something is expensive? I always considered it the lightest weight and most accurate. Date involves object instantiation and Ticks only resolves 1/60th second.