File size: 1,458 Bytes
f918b86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// SPDX-License-Identifier: Apache-2.0
// Run the browser core in Node on a prediction file and print the bundle (for parity tests).
// usage: node tests/node_bench.mjs <pred> <segment> [target] [tRef] [tPred] [invert]
import fs from 'node:fs';
import * as C from '../lib/bench-core.js';
const [pred, segment, target = 'ink', tRef = '0.5', tPred = '0.5', inv = '0'] = process.argv.slice(2);
const root = new URL('..', import.meta.url).pathname;
const index = JSON.parse(fs.readFileSync(root + 'data/bench/index.json'));
const seg = index.segments[segment];
const rd = (f) => fs.readFileSync(root + f);
const ref = await C.decodeBytes(rd(seg.layers.ink.file));
const tgt = target === 'ink' ? ref : await C.decodeBytes(rd(seg.layers[target].file));
const buf = fs.readFileSync(pred);
let P = await C.decodeBytes(buf);
if (inv === '1') P = { ...P, d: P.d.map((v) => 1 - v) };
const t0 = Date.now();
const al = await C.align(tgt, P);
const { val, m } = C.applyAlignment(ref, P, al);
const met = C.metrics(ref, val, m, +tRef, +tPred, seg.pxPerMM);
const b = C.makeBundle({ index, segment, refLayer: seg.layers.ink, targetLayer: seg.layers[target], target, predInfo: P.info, predHash: await C.sha256(buf), predName: pred.split('/').pop(), invert: inv === '1', model: { name: 'unspecified' }, al, method: 'auto', alignNcc: C.rnd(C.ncc(tgt, val, m, 1), 6), met, annotations: [], impl: 'node' });
console.error('ms', Date.now() - t0);
console.log(JSON.stringify(b));