Skip to content

Commit fbff9ac

Browse files
committed
better profiling messages
1 parent 0e3f214 commit fbff9ac

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

profile-method-call.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
1-
(function profileMethodCall() {
2-
var object = window.primesApp;
3-
console.assert(object, 'cannot find object to profile');
1+
(function profileMethodCall(root) {
2+
'use strict';
43

4+
var name = 'primesApp';
55
var methodName = 'findFirstPrimes';
6+
7+
var object = root[name];
8+
console.assert(object, 'cannot find object ' + name + ' to profile');
9+
610
var originalMethod = object[methodName];
711
console.assert(typeof originalMethod === 'function', 'cannot find method ' + methodName);
12+
813
object[methodName] = function () {
914
console.profile(methodName);
1015
originalMethod.call(object);
1116
console.profileEnd(methodName);
12-
// restore original methodName
17+
1318
object[methodName] = originalMethod;
19+
console.log('restored the original method call');
1420
};
15-
}());
21+
console.log('wrapped', name + '.' + methodName + ' in profiling calls');
22+
}(this));

time-method-call.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
1-
(function timeMethodCall() {
2-
var object = window.primesApp;
3-
console.assert(object, 'cannot find object to profile');
1+
(function timeMethodCall(root) {
2+
'use strict';
43

4+
var name = 'primesApp';
55
var methodName = 'findFirstPrimes';
6+
7+
var object = root[name];
8+
console.assert(object, 'cannot find object ' + name + ' to profile');
9+
610
var originalMethod = object[methodName];
711
console.assert(typeof originalMethod === 'function', 'cannot find method ' + methodName);
12+
813
object[methodName] = function () {
914
console.time(methodName);
1015
originalMethod.call(object);
1116
console.timeEnd(methodName);
12-
// restore original methodName
17+
1318
object[methodName] = originalMethod;
19+
console.log('restored the original method call');
1420
};
15-
}());
21+
console.log('wrapped', name + '.' + methodName + ' in timing calls');
22+
}(this));

0 commit comments

Comments
 (0)