Download tests/node_bench.mjs from SharpMeow/unroll: direct link, hf CLI and curl.
- Browser
- Download file 1.46 kB
-
https://huggingface.co/spaces/SharpMeow/unroll/resolve/main/tests/node_bench.mjs
- Command line
-
hf download hf://spaces/SharpMeow/unroll/tests/node_bench.mjs
-
curl -L -o node_bench.mjs https://huggingface.co/spaces/SharpMeow/unroll/resolve/main/tests/node_bench.mjs
1.46 kB
| // 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)); | |