@browserless/benchmark 10.9.18 → 10.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@browserless/benchmark",
3
3
  "description": "Performance benchmarking tool for headless browser automation. Measure CPU, GPU, timing, and screenshot performance across configurations.",
4
4
  "homepage": "https://browserless.js.org/#/?id=benchmark",
5
- "version": "10.9.18",
5
+ "version": "10.10.0",
6
6
  "main": "src/index.js",
7
7
  "author": {
8
8
  "email": "josefrancisco.verdu@gmail.com",
@@ -40,7 +40,6 @@
40
40
  "nanobench": "latest",
41
41
  "p-all": "3",
42
42
  "percentile": "latest",
43
- "picocolors": "latest",
44
43
  "pretty-ms": "7",
45
44
  "process-stats": "latest",
46
45
  "sieve-of-eratosthenes": "latest",
@@ -57,5 +56,5 @@
57
56
  "test": "exit 0"
58
57
  },
59
58
  "license": "MIT",
60
- "gitHead": "f5e8cd0788e4bad3b3ad9b007943754f96653817"
59
+ "gitHead": "9b80e677418f2defb804d39043680fe65e3e277b"
61
60
  }
package/src/adblock.js ADDED
@@ -0,0 +1,89 @@
1
+ 'use strict'
2
+
3
+ const fs = require('fs')
4
+ const path = require('path')
5
+ const createBrowserless = require('browserless')
6
+
7
+ const urls = [
8
+ 'https://as.com/',
9
+ 'https://live.deutsche-boerse.com/',
10
+ 'https://stackoverflow.com/',
11
+ 'https://www.bonilista.com/',
12
+ 'https://www.cookiebot.com/',
13
+ 'https://www.digitalocean.com/',
14
+ 'https://www.eltiempo.com/',
15
+ 'https://www.ft.com/',
16
+ 'https://www.hetzner.com/',
17
+ 'https://www.miltoneducation.com',
18
+ 'https://www.publico.es/',
19
+ 'https://www.sport.es/es/'
20
+ ]
21
+
22
+ const takeScreenshot = async ({ url, browserless, withAdblock }) => {
23
+ const { screenshot, destroyContext } = await browserless.createContext()
24
+ const label = url.replace(/https?:\/\//, '').replace(/\W+/g, '_')
25
+ let screenshotPath = path.join(outDir, `${label}.png`)
26
+ screenshotPath = withAdblock
27
+ ? screenshotPath.replace('.png', '-adblock.png')
28
+ : screenshotPath.replace('.png', '-no-adblock.png')
29
+ const start = Date.now()
30
+ await screenshot(url, { path: screenshotPath, adblock: withAdblock, waitForTimeout: 1500 })
31
+ const responseTime = Date.now() - start
32
+ await destroyContext()
33
+
34
+ return {
35
+ url,
36
+ screenshotPath,
37
+ responseTime
38
+ }
39
+ }
40
+
41
+ const outDir = path.join(__dirname, 'adblock-benchmark-results')
42
+ if (!fs.existsSync(outDir)) fs.mkdirSync(outDir)
43
+
44
+ async function bench () {
45
+ const browserless = await createBrowserless()
46
+
47
+ // Use a map to group results by url and screenshotPath
48
+ const resultsMap = new Map()
49
+
50
+ for (const withAdblock of [true, false]) {
51
+ for (const url of urls) {
52
+ const data = await takeScreenshot({ url, browserless, withAdblock })
53
+ const key = `${data.url}|${data.screenshotPath.replace(/-(adblock|no-adblock)\.png$/, '')}`
54
+ let entry = resultsMap.get(key)
55
+ if (!entry) {
56
+ entry = {
57
+ url: data.url,
58
+ screenshotPath: data.screenshotPath.replace(
59
+ /-(adblock|no-adblock)\.png$/,
60
+ '-adblock.png'
61
+ ),
62
+ responseTime: {}
63
+ }
64
+ resultsMap.set(key, entry)
65
+ }
66
+ entry.responseTime[withAdblock ? 'adblock' : 'no-adblock'] = data.responseTime
67
+ // Optionally, update screenshotPath for adblock/no-adblock if you want both paths
68
+ // entry[`screenshotPath_${withAdblock ? 'adblock' : 'no_adblock'}`] = data.screenshotPath
69
+ console.log(
70
+ `Done: ${url} (${withAdblock ? 'adblock' : 'no-adblock'}: ${data.responseTime}ms)`
71
+ )
72
+ }
73
+ }
74
+
75
+ await browserless.close()
76
+
77
+ const results = Array.from(resultsMap.values())
78
+ fs.writeFileSync(path.join(outDir, 'results.json'), JSON.stringify(results, null, 2))
79
+ console.log('Benchmark complete. Results saved to', outDir)
80
+ }
81
+
82
+ bench()
83
+ .then(() => {
84
+ process.exit(0)
85
+ })
86
+ .catch(err => {
87
+ console.error('Error during benchmark:', err)
88
+ process.exit(1)
89
+ })
package/src/colors.js ADDED
@@ -0,0 +1,17 @@
1
+ 'use strict'
2
+
3
+ const { styleText } = require('node:util')
4
+
5
+ const gray = str => styleText('gray', str)
6
+
7
+ const white = str => styleText('white', str)
8
+
9
+ const green = str => styleText('green', str)
10
+
11
+ const red = str => styleText('red', str)
12
+
13
+ const yellow = str => styleText('yellow', str)
14
+
15
+ const label = (text, color) => styleText(['inverse', 'bold', color], ` ${text.toUpperCase()} `)
16
+
17
+ module.exports = { gray, white, green, red, yellow, label }
package/src/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  const createBrowserless = require('browserless')
4
4
  const processStats = require('process-stats')
5
5
  const asciichart = require('asciichart')
6
- const { gray } = require('picocolors')
6
+ const { gray } = require('./colors')
7
7
  const prettyMs = require('pretty-ms')
8
8
  const Measured = require('measured')
9
9
  const pAll = require('p-all')