Timer: Difference between revisions
Jump to navigation
Jump to search
no edit summary
No edit summary |
|||
| Line 68: | Line 68: | ||
print("Elapsed time in seconds: ", end - start) | print("Elapsed time in seconds: ", end - start) | ||
</pre> | </pre> | ||
== Javascript == | |||
<pre> | |||
function sleep(ms) { | |||
return new Promise(resolve => setTimeout(resolve, ms)); | |||
} | |||
// 1 second = 1000 ms | |||
var startTimeInMs = Date.now(); | |||
await sleep(2000); | |||
var endTimeInMs = Date.now(); | |||
var durationInMs = endTimeInMs - startTimeInMs; | |||
console.log('durationInMs: ' + durationInMs); | |||
var durationInSecond = durationInMs / 1000; | |||
console.log('durationInSecond: ' + durationInSecond); | |||
</pre> | |||
Reference | |||
* [https://www.educative.io/edpresso/what-is-the-javascript-alternative-to-the-sleep-function What is the Javascript alternative to the sleep function?] | |||
== Java == | == Java == | ||