Skip to content

Commit 4ab2c4f

Browse files
committed
WIP: refactoring
1 parent 78b3c6f commit 4ab2c4f

21 files changed

+358
-137
lines changed

package-lock.json

Lines changed: 197 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@
3434
"homepage": "https://github.com/jscriptcoder/HTTP-vs-WebSockets-performance#readme",
3535
"dependencies": {
3636
"axios": "^0.20.0",
37+
"chalk": "^4.1.0",
3738
"node-fetch": "^2.6.1",
3839
"socket.io-client": "^2.3.0",
3940
"websocket": "^1.0.32",
40-
"ws": "^7.3.1"
41+
"ws": "^7.3.1",
42+
"yargs": "^16.0.3"
4143
},
4244
"devDependencies": {
4345
"@babel/core": "^7.11.6",

src/clients/PerformanceTimer.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const { PerformanceObserver, performance } = require('perf_hooks')
2+
3+
function performanceObserverCallback(items) {
4+
console.log('Timer stopped. Measuring...')
5+
console.log(`Duration: ${items.getEntries()[0].duration}`)
6+
performance.clearMarks()
7+
}
8+
9+
export default class PerformanceTimer {
10+
startMark = 'START'
11+
endMark = 'END'
12+
13+
constructor() {
14+
this.obs = new PerformanceObserver(performanceObserverCallback)
15+
this.obs.observe({ entryTypes: ['measure'] })
16+
}
17+
18+
start() {
19+
console.log('Timer started...')
20+
performance.mark(this.startMark)
21+
}
22+
23+
end() {
24+
performance.mark(this.endMark)
25+
performance.measure(`${this.startMark} to ${this.endMark}`, this.startMark, this.endMark)
26+
}
27+
}

0 commit comments

Comments
 (0)