1 | #!/usr/bin/env node
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | const fs = require('fs');
|
7 |
|
8 |
|
9 | const fetch = require('node-fetch');
|
10 | const JSSoup = require('jssoup').default;
|
11 |
|
12 |
|
13 | const BENCHMARK_MOBILE_URL = 'https://www.notebookcheck.net/Mobile-Graphics-Cards-Benchmark-List.844.0.html?type=&sort=&professional=2&showClassDescription=1&deskornote=3&archive=1&perfrating=1&or=0&showBars=1&3dmark13_ice_gpu=1&3dmark13_cloud_gpu=1&3dmark13_fire_gpu=1&3dmark11_gpu=1&gpu_fullname=1&architecture=1&pixelshaders=1&vertexshaders=1&corespeed=1&boostspeed=1&memoryspeed=1&memorybus=1&memorytype=1&directx=1';
|
14 |
|
15 |
|
16 | const BENCHMARK_DESKTOP_URL = 'https://www.notebookcheck.net/Mobile-Graphics-Cards-Benchmark-List.844.0.html?type=&sort=&showClassDescription=1&deskornote=4&archive=1&perfrating=1&or=0&showBars=1&3dmark13_ice_gpu=1&3dmark13_cloud_gpu=1&3dmark13_fire_gpu=1&3dmark11_gpu=1&gpu_fullname=1&architecture=1&pixelshaders=1&vertexshaders=1&corespeed=1&boostspeed=1&memoryspeed=1&memorybus=1&memorytype=1&directx=1';
|
17 |
|
18 | function collectBenchmark(url) {
|
19 | return new Promise((resolve, reject) => fetch(url)
|
20 | .then(response => response.text())
|
21 | .then((html) => {
|
22 | const soup = new JSSoup(html.replace('<!DOCTYPE html>', ''));
|
23 | const table = soup.find('table');
|
24 | const inputs = table.findAll('input');
|
25 |
|
26 | const benchmark = inputs.map((input) => {
|
27 | const score = input.previousElement.text.replace(' ', '').replace('*', '');
|
28 | let name = '';
|
29 |
|
30 | input.previousElement.contents.forEach((row) => {
|
31 | if (row.nextElement.text) {
|
32 | name = row.nextElement.text;
|
33 | }
|
34 | });
|
35 |
|
36 | return `${score} - ${name}`;
|
37 | });
|
38 |
|
39 | resolve(benchmark);
|
40 | })
|
41 | .catch((error) => {
|
42 | reject(new Error(error.message));
|
43 | }));
|
44 | }
|
45 |
|
46 | Promise.all([collectBenchmark(BENCHMARK_DESKTOP_URL), collectBenchmark(BENCHMARK_MOBILE_URL)]).then(
|
47 | (result) => {
|
48 | const output = './src/benchmark.js';
|
49 | const data = `
|
50 |
|
51 | // Scraped from https://www.notebookcheck.net/
|
52 | // Mobile GPU benchmark: ${BENCHMARK_MOBILE_URL}
|
53 | // Desktop GPU benchmark: ${BENCHMARK_DESKTOP_URL}
|
54 |
|
55 |
|
56 | export const BENCHMARK_SCORE_DESKTOP = [
|
57 | ${result[0].reverse().map(entry => `\n\'${entry}\'`)}
|
58 | ];
|
59 |
|
60 | export const BENCHMARK_SCORE_MOBILE = [
|
61 | ${result[1].reverse().map(entry => `\n\'${entry}\'`)}
|
62 | ];
|
63 | `;
|
64 |
|
65 | fs.writeFile(output, data, (error) => {
|
66 | if (!error) {
|
67 | console.log(`Written file to ${output}`);
|
68 | } else {
|
69 | console.error(error);
|
70 | }
|
71 | });
|
72 | },
|
73 | );
|