-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapplication.js
95 lines (84 loc) · 1.98 KB
/
application.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
import Ember from 'ember';
var MyThing = Ember.Object.extend({
d: function() {
return this.get("a") + this.get("b");
}.property("a", "b")
});
var listItems = [];
for (var i=0; i<50; i++) {
listItems.pushObject(MyThing.create({
a: "a" + i,
b: "b" + i,
c: "c" + i
}));
}
function waitForRender() {
return new Ember.RSVP.Promise(resolve => Ember.run.schedule('afterRender', resolve));
}
export default Ember.Controller.extend({
listItems,
showList: false,
timings: [],
manyTimes: 10,
fixedDuration: 10,
emberVersion: Ember.VERSION,
emberPerf: Ember.inject.service(),
isProdBuild: Ember.computed(function() {
try {
Ember.assert("are we running prod?", false);
return true;
} catch (err) {
return false;
}
}),
stats: Ember.computed('timings.[]', function() {
let timings = this.get('timings');
if (timings.length === 0) {
return null;
}
return {
mean: Math.floor(timings.reduce((a,b) => a + b.ms, 0) / timings.length)
};
}),
resetTest() {
this.set('showList', false);
return waitForRender();
},
runTest() {
let emberPerf = this.get('emberPerf');
return this.resetTest().then(() => {
this.set('showList', true);
return emberPerf.measureRender();
})
.then((results) => {
this.get('timings').pushObject({ ms: results.elapsedTime });
});
},
actions: {
clear() {
this.resetTest();
this.set('timings', []);
},
runOneTest() {
this.runTest();
},
renderMany() {
let counter = this.get('manyTimes');
let step = () => this.runTest().then(() => {
if (--counter > 0) {
return step();
}
});
return step();
},
renderFixed() {
let endAt = new Date().getTime() + this.get('fixedDuration')*1000;
let step = () => this.runTest().then(() => {
if (new Date() < endAt) {
return step();
}
});
return step();
}
}
});