Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add timeCalls option for measuring performance

  • Loading branch information...
commit c4b54aeea3ed1cf27116938301323761f496d807 1 parent 4468149
Blixt authored
Showing with 18 additions and 1 deletion.
  1. +18 −1 index.js
View
19 index.js
@@ -66,9 +66,12 @@
function sendCallsToWorker(worker, options) {
var cache = {},
callbacks = {},
+ timers,
nextCallId = 1,
fakeProxy;
+ if (options.timeCalls) timers = {};
+
if (typeof Proxy == 'undefined') {
// If we have no Proxy support, we have to pre-define all the functions.
fakeProxy = {};
@@ -101,6 +104,12 @@
callbacks[id] = args.pop();
}
+ if (options.timeCalls) {
+ var timerId = name + '(' + args + ')';
+ timers[id] = timerId;
+ console.time(timerId);
+ }
+
worker.postMessage({callId: id, call: name, arguments: args}, opt_transferList);
}
@@ -109,10 +118,16 @@
if (message.callResponse) {
var callId = message.callResponse;
+
if (callbacks[callId]) {
callbacks[callId].apply(null, message.arguments);
delete callbacks[callId];
}
+
+ if (options.timeCalls && timers[callId]) {
+ console.timeEnd(timers[callId]);
+ delete timers[callId];
+ }
} else if (message.functionNames) {
message.functionNames.forEach(function (name) {
fakeProxy[name] = getHandler(null, name);
@@ -142,7 +157,9 @@
// the proxy functions available when Proxy is not supported. Note that
// this is generally not needed since the worker will also publish its
// known functions.
- functionNames: []
+ functionNames: [],
+ // Call console.time and console.timeEnd for calls sent though the proxy.
+ timeCalls: false
};
if (opt_options) {
Please sign in to comment.
Something went wrong with that request. Please try again.