# So ElapsedTime is faster than DeltaTime?

I did this simple test to see if DeltaTime matched up with ElapsedTime speed-wise.

``````if ElapsedTime < 1 then
print("E:"..ElapsedTime.." D:"..DeltaTime)
end
``````

this was one of the end results

E:0.986272 D:0.0163853

A prior one was similar.

E:0.0333333 D:0.0166667

this one was at the very beginning.
Surprisingly while you could multiply by 2 here at the beginning to get them to match
up; at the end its a much greater gap that multiplying by 2 wouldn’t fix.

I’ve suspected this for a while but now it is confirmed…

Why is ElapsedTime so much faster than DeltaTime?

Hi @beu5mi,

DeltaTime gives the time since the last draw call (around 1/60th of a second if all is fine :P), while ElapsedTime gives the time since the program started.

When you start your program, the first print will be the same, then ElapsedTime will obviously grow until the end of your program, where ElapsedTime has reached 1second and DeltaTime is still approx 1/60th of a second

Cheers,
Xavier

Hello @beu5mi. I do not follow your post. `DeltaTime` is the time since `draw()` was last called. It is often about 1/60th of a second. `ElapsedTime` is the sum of all the `DeltaTime` values since the code was run.

But if you stay in the draw function then DeltaTime shouldn’t change right?

Also I find it hard to believe that its 1/60 of a second given the results I received from the tests I ran. how do you reset the ElapsedTime? I’ve tried going back to setup.

.@Simeon Can you reset the ElapsedTime in code?

.@beu5mi , Well, you should increment a variable by DeltaTime.

``````
function setup()
time = 0
end

function draw()
output.clear()
print(time)
time = time + DeltaTime
if time > 10 then
time = 0
end

end

``````

this will reset the time variable to 0 every 10 seconds

Cheers

You can not reset `ElapsedTime`. You can keep track of its ‘initial’ value in a variable, and calculate the difference between its ‘current’ value and that value.

``````
function setup()
startTime = ElapsedTime
end

function draw()
background(0)
local time = ElapsedTime - startTime
if time > 2 then
print("Event!")
startTime = ElapsedTime
end
end

``````
``````But if you stay in the draw function then DeltaTime shouldn't change right?
``````

Codea tries to execute the draw() function every 1/60th of a second.
You can’t “stay” in the draw() function, you just pass through it every frame.

``````
Also I find it hard to believe that its 1/60 of a second given the results I received from the tests I ran.

...

A prior one was similar.

E:0.0333333 D:0.0166667
``````

1/60 = 0.01666666666667

.@Xavier thanks thats from the triangulate example is’nt it

.@beu5mi. The values referred to by `ElapsedTime` and `DeltaTime` do not change automatically during the execution of `draw()`.