Skip to content
Advertisement

How can I turn an execution time-counter into one or two functions?

I use this code often:

JavaScript

This gives the time a block of code took to execute.

I’m trying to turn that process into one or two functions but I’m having a hard time conceptualizing it.

Something like this but it always gives 0.0:

JavaScript

Advertisement

Answer

start_timer returns the starting time, You need to save it inside a variable.

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement