Skip to content

Commit aa03a74

Browse files
authored
Fix fps emit (#16)
* Tweak fps-emit logic to add an extra entry when done * Update fps-emit build settings * Bump fps-emit version * Add fps-emit note * Fix horribly-wrong weighted average logic
1 parent 2811649 commit aa03a74

File tree

5 files changed

+28
-17
lines changed

5 files changed

+28
-17
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,8 @@ Also, `index.html` must be modified to include these lines:
9898
<script type="text/javascript" src="react-dom.production.min.js"></script>
9999
<script type="text/javascript" src="react-redux.min.js"></script>
100100
```
101+
102+
103+
If you need to make changes to the `fps-emit` package, bump the version number in its `package.json`,
104+
then update each benchmark to use the newest version using `yarn upgrade-interactive` and selecting `fps-emit`
105+
for an update. Then rebuild all the benchmarks using `yarn initialize`

fps-emit/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
{
22
"name": "fps-emit",
33
"private": true,
4-
"version": "1.0.0",
4+
"version": "1.0.1",
55
"description": "fps emitter",
66
"main": "src/index.js",
77
"scripts": {
8-
"build": "cross-env BABEL_ENV=rollup NODE_ENV=production rollup -c -o dist/fps-emit.min.js",
8+
"build:commonjs": "cross-env BABEL_ENV=commonjs babel src --out-dir lib",
9+
"build:es": "babel src --out-dir es",
10+
"build:umd:min": "cross-env NODE_ENV=production rollup -c -o dist/react-redux.min.js",
11+
"build": "yarn run build:commonjs && yarn run build:es && yarn run build:umd:min",
912
"test": "echo \"Error: no test specified\" && exit 1"
1013
},
1114
"author": "Gregory Beaver <[email protected]>",

fps-emit/src/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ fps.on("update", function(FPS) {
1313
});
1414

1515
const getFpsStats = () => {
16+
// fake a final entry with the same FPS
17+
const finalFPS = fps.__fps
18+
marker.mark("FPS", {
19+
details: { FPS : finalFPS, isFinal : true }
20+
});
21+
1622
const logData = performance.getEntriesByType("mark").map(entry => {
1723
const meta = marker.getEntryMetadata(entry);
1824
return {

runBenchmarks.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,32 +83,29 @@ async function runBenchmarks() {
8383

8484
const averageFPS = fpsValuesWithoutFirst.reduce((sum, entry) => sum + entry.FPS, 0) / fpsValuesWithoutFirst.length || 0;
8585

86-
const fpsValuesPlusFakeEntries = [
87-
...fpsValuesWithoutFirst,
88-
{...lastEntry, timestamp : length * 1000}
89-
]
90-
91-
const pairwiseEntries = pairwise(fpsValuesPlusFakeEntries);
86+
const pairwiseEntries = pairwise(fpsValuesWithoutFirst);
9287

9388
const fpsValuesWithDurations = pairwiseEntries.map(pair => {
9489
const [first, second] = pair;
9590
const duration = second.timestamp - first.timestamp;
91+
const durationSeconds = duration / 1000.0
9692

97-
return {FPS : second.FPS, duration}
93+
return {FPS : first.FPS, durationSeconds}
9894
})
9995

10096
const sums = fpsValuesWithDurations.reduce( (prev, current) => {
97+
const weightedFPS = current.FPS * current.durationSeconds;
98+
10199
return {
102-
FPS : prev.FPS + current.FPS,
103-
duration : prev.duration + current.duration
100+
weightedFPS : prev.weightedFPS + weightedFPS,
101+
durationSeconds : prev.durationSeconds + current.durationSeconds,
104102
}
105-
}, {FPS : 0, duration : 0});
103+
}, {FPS : 0, weightedFPS : 0, durationSeconds : 0});
106104

107-
const durationSeconds = sums.duration / 1000.0;
108105

109-
const weightedFPS = sums.FPS / durationSeconds;
106+
const weightedFPS = sums.weightedFPS / sums.durationSeconds;
110107

111-
const fps = {averageFPS, weightedFPS, values : fpsValues}
108+
const fps = {averageFPS, weightedFPS, values : fpsValuesWithoutFirst}
112109

113110
versionPerfEntries[version] = {fps, profile : {categories}};
114111

utils/server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ module.exports = {
6464
) || []
6565

6666
fpsValues = fpsStatsEntries.map(entry => {
67-
const {FPS} = entry.meta.details;
68-
return {FPS, timestamp : entry.timeStamp};
67+
const {FPS, isFinal} = entry.meta.details;
68+
return {FPS, timestamp : entry.timeStamp, isFinal};
6969
});
7070

7171
await page.close();

0 commit comments

Comments
 (0)