-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworker.js
More file actions
30 lines (26 loc) · 792 Bytes
/
worker.js
File metadata and controls
30 lines (26 loc) · 792 Bytes
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
export default {
fetch: async req => {
const { pathname, search } = new URL(req.url)
let perf = []
for (let i = 0; i < 20; i++) {
const startTime = Date.now()
const data = await fetch('https:/' + pathname + search, req)
const time = Date.now() - startTime
perf.push(time)
}
console.log(perf)
const first = perf[0]
const sorted = perf.sort((a, b) => a - b)
console.log(sorted)
return new Response(JSON.stringify({
target: 'https:/' + pathname + search,
first,
min: sorted[0],
p25: sorted[4],
med: sorted[9],
avg: (perf.reduce((acc, x) => acc + x, 0)) / 20,
p75: sorted[15],
max: sorted[19],
}, null, 2), { headers: { 'content-type': 'application/json' }})
}
}