forked from elavoie/photon-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dynamic-profile.js
110 lines (86 loc) · 2.56 KB
/
dynamic-profile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
function init() {
function instr_new(f) {
var counter = 0;
var g = function () {
counter++;
return f.call(this);
};
g.revert = function () {
return f;
};
g.count = function () {
return counter;
};
return g;
}
function instr1(f) {
var counter = 0;
var g = function (x) {
counter++;
return f.call(this, x);
};
g.revert = function () {
return f;
};
g.count = function () {
return counter;
};
return g;
}
print("Profiling the compiler");
Object.prototype.__clone_fast__ = instr_new(Object.prototype.__clone_fast__);
Object.prototype.__new_default__ = instr_new(Object.prototype.__new_default__);
Object.prototype.__get__ = instr1(Object.prototype.__get__);
eval("1+2");
print("__clone_fast__ called " + Object.prototype.__clone_fast__.count() + " times");
print("__new_default__ called " + Object.prototype.__new_default__.count() + " times");
print("__get__ called " + Object.prototype.__get__.count() + " times");
Object.prototype.__clone_fast__ = Object.prototype.__clone_fast__.revert();
Object.prototype.__new_default__ = Object.prototype.__new_default__.revert();
Object.prototype.__get__ = Object.prototype.__get__.revert();
print("Mesuring the overhead of profiling");
var g = instr1(Object.prototype.__get__);
var time = currentTimeMillis;
var o = {foo:42};
var n = 5000000;
var start = time();
for (var i = 0; i < n; ++i)
{
o.foo;
}
var end = time();
print("Baseline: " + (end - start) + "s");
Object.prototype.__get__ = g;
var start = time();
for (var i = 0; i < n; ++i)
{
o.foo;
}
var end = time();
//print("Performed operations: " + n);
//print("Profiled operations: " + g.count());
print("Profiled: " + (end - start) + "s");
Object.prototype.__get__ = g.revert();
var start = time();
for (var i = 0; i < n; ++i)
{
o.foo;
}
var end = time();
print("Reverted: " + (end - start) + "s");
};
init();
//print(eval("1+2"));
//print(Object.prototype.__clone_fast__.count());
//print(Object.prototype.__new_default__.count());
//print(Object.prototype.__get__.count());
//print(eval("1+2"));
//print(eval("1+2"));
/*
print("Object.prototype.__new__ called "
+ count() + " times");
*/
/*
Object.prototype.__new__ = revert();
*/
//o = {};