diff options
author | ToadKing <toadking@toadking.com> | 2013-08-11 17:55:38 -0400 |
---|---|---|
committer | ToadKing <toadking@toadking.com> | 2013-08-11 17:55:38 -0400 |
commit | 38adc363fae517382e5b59308389d1ceb75a7461 (patch) | |
tree | f52ac9508cc3bedcac5dfb00516fef2f8f83b704 /src/library.js | |
parent | 5bb74d2c5ed57a7b52e1a3d01404edfb7a9945ea (diff) |
use performance timers for usleep if available
Diffstat (limited to 'src/library.js')
-rw-r--r-- | src/library.js | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/library.js b/src/library.js index fedb8760..815badc1 100644 --- a/src/library.js +++ b/src/library.js @@ -1413,9 +1413,16 @@ LibraryManager.library = { // http://pubs.opengroup.org/onlinepubs/000095399/functions/usleep.html // We're single-threaded, so use a busy loop. Super-ugly. var msec = useconds / 1000; - var start = Date.now(); - while (Date.now() - start < msec) { - // Do nothing. + if (ENVIRONMENT_IS_WEB && window['performance'] && window['performance']['now']) { + var start = window['performance']['now'](); + while (window['performance']['now']() - start < msec) { + // Do nothing. + } + } else { + var start = Date.now(); + while (Date.now() - start < msec) { + // Do nothing. + } } return 0; }, |