-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark.js
53 lines (43 loc) · 1.44 KB
/
benchmark.js
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
'use strict';
const { execSync } = require( 'child_process' );
const puppeteer = require( 'puppeteer' );
const argv = require( 'minimist' )( process.argv.slice( 2 ) );
const fs = require( 'fs' );
// task to benchmark
const bench_task = ( async ( ) =>
{
var tstart = process.hrtime();
const browser = await puppeteer.launch({ headless: false, executablePath: '/var/bench/chromium-browser/chromium-browser-v7' });
var tlaunch = process.hrtime( tstart );
const page = await browser.newPage();
await page.goto( 'file:///home/cristidbr/Desktop/pi4_bench/benchmark.htm' );
await page.evaluate( () =>
{
parseInt( !! window.hasOwnProperty( 'benchReady' ) )
});
var tend = process.hrtime( tstart );
await browser.close();
// clear cached memory
execSync( 'sync ; echo 3 | sudo tee /proc/sys/vm/drop_caches' );
return [ tlaunch, tend ];
});
// tasks runner
( async ( ) =>
{
const bench_runs = argv.runs || 1;
var mapTimestamp = ( d ) => { return parseFloat( `${ d[0] }.${ d[1] }` ); };
var results = [];
for( var i = 0; i < bench_runs; i++ )
{
let result = await bench_task();
results.push( result.map( mapTimestamp ) );
}
var bench_data = JSON.stringify( {
launch: results
});
fs.writeFile( 'bench.json', bench_data, ( err ) =>
{
if( err ) throw err;
console.log( 'Benchmark ended' );
});
})();