Skip to content

Commit 6483bb0

Browse files
committed
added time method call snippet
1 parent cbbe4d4 commit 6483bb0

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Read [Code Snippets tutorial][1] and
1616
* [first-paint.js](first-paint.js) - time from page reload to first visible contents.
1717
* [timing.js](timing.js) - Detailed page timing information,
1818
from [addyosmani/timing.js](https://github.com/addyosmani/timing.js).
19+
* [time-method-call.js](time-method-call.js) - measures single method call time.
1920
* [local-storage-size.js](local-storage-size.js) - measures size of the strings in the `localStorage`.
2021
* [expensive-keys.js](expensive-keys.js) - measures how much space individual keys and their values
2122
take up in a collection of objects, read [Measuring Space Allocation][measure].

time-method-call.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
(function profileMethodCall() {
2+
var object = primesApp;
3+
var methodName = 'findFirstPrimes';
4+
var originalMethod = object[methodName];
5+
console.assert(typeof originalMethod === 'function', 'cannot find method ' + methodName);
6+
object[methodName] = function () {
7+
console.time(methodName);
8+
originalMethod.call(object);
9+
console.timeEnd(methodName);
10+
// restore original methodName
11+
object[methodName] = originalMethod;
12+
};
13+
}());

0 commit comments

Comments
 (0)