aboutsummaryrefslogtreecommitdiff
path: root/src/library.js
diff options
context:
space:
mode:
authorToadKing <toadking@toadking.com>2013-08-11 17:55:38 -0400
committerToadKing <toadking@toadking.com>2013-08-11 17:55:38 -0400
commit38adc363fae517382e5b59308389d1ceb75a7461 (patch)
treef52ac9508cc3bedcac5dfb00516fef2f8f83b704 /src/library.js
parent5bb74d2c5ed57a7b52e1a3d01404edfb7a9945ea (diff)
use performance timers for usleep if available
Diffstat (limited to 'src/library.js')
-rw-r--r--src/library.js13
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;
},