Skip to content

Commit 4eb7c82

Browse files
committed
added profile separate calls method
1 parent ee75aa6 commit 4eb7c82

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ from [addyosmani/timing.js](https://github.com/addyosmani/timing.js).
3939
* [profile-method-call.js](profile-method-call.js) - profiles a single method call.
4040
* [profile-prototype-method.js](profile-prototype-method.js) - profiles a single method call
4141
that is on a prototype object, not on an instance.
42+
* [profile-separate-calls.js](profile-separate-calls.js) can profile actions where separate
43+
method calls start and stop the operation.
4244

4345
### Storage measurements
4446

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "code-snippets",
33
"main": "first-paint.js",
4-
"version": "0.3.1",
4+
"version": "0.3.2",
55
"homepage": "https://github.com/bahmutov/code-snippets",
66
"license": "MIT",
77
"ignore": [

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "code-snippets",
33
"description": "Chrome DevTools code snippets ",
4-
"version": "0.3.1",
4+
"version": "0.3.2",
55
"author": "Gleb Bahmutov <gleb.bahmutov@gmail.com>",
66
"bugs": {
77
"url": "https://github.com/bahmutov/code-snippets/issues"

profile-separate-calls.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// time action with separate start and finish callbacks
2+
// for example
3+
/*
4+
worker.onmessage = function (e) {
5+
console.log('worker has finished');
6+
renderPrimes(e.data);
7+
};
8+
document.addEventListener('DOMContentLoaded', function() {
9+
document.querySelector('#find').addEventListener('click', function () {
10+
var n = Number(document.querySelector('#n').value);
11+
primesApp.findFirstPrimes(n);
12+
});
13+
});
14+
15+
you can profile as
16+
17+
timeSeparateCallback(primesApp, 'findFirstPrimes', worker, 'onmessage');
18+
*/
19+
(function timeSeparateCallback(obj1, methodName1, obj2, methodName2) {
20+
'use strict';
21+
22+
console.assert(obj1, 'missing first object');
23+
console.assert(obj2, 'missing second object');
24+
25+
var m1 = obj1[methodName1];
26+
console.assert(typeof m1 === 'function', 'cannot find first method ' + methodName1);
27+
var m2 = obj2[methodName2];
28+
console.assert(typeof m2 === 'function', 'cannot find first method ' + methodName2);
29+
30+
obj1[methodName1] = function () {
31+
console.profile('separate');
32+
console.time('separate');
33+
m1.apply(obj1, arguments);
34+
};
35+
36+
obj2[methodName2] = function () {
37+
console.timeEnd('separate');
38+
console.profileEnd('separate');
39+
m2.apply(obj2, arguments);
40+
};
41+
42+
console.log('wrapped', methodName1, 'and', methodName2, 'in timing calls');
43+
44+
// modify the arguments below
45+
}(window, 'postMessage', window, 'onmessage'));

0 commit comments

Comments
 (0)