mirror of
https://github.com/2234839/web-font.git
synced 2026-09-04 14:53:32 +08:00
千字文 ttf 0.396ms→0.252ms(-36%),woff2 不受影响(不走 node Buffer 路径)。 Writer 的 ArrayBuffer 精确分配为 ttfSize(offset=0),getBuffer 返回完整 buffer, Buffer.from 共享底层内存无 over-exposure 风险。SSIM 全部不变。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
17 lines
1.1 KiB
TypeScript
17 lines
1.1 KiB
TypeScript
import { performance } from 'perf_hooks';
|
|
import { readFileSync } from 'fs';
|
|
import { fontSubset } from './backend/font_util/font.js';
|
|
const buf = readFileSync('font/令东齐伋复刻体.ttf');
|
|
const ab = buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
|
|
const cases: [string,string,any][] = [
|
|
['千字文woff2','天地玄黄宇宙洪荒日月盈昃辰宿列张寒来暑往秋收冬藏闰余成岁律吕调阳云腾致雨露结为霜金生丽水玉出昆冈剑号巨阙珠称夜光果珍李柰菜重芥姜海咸河淡鳞潜羽翔',{sourceType:'ttf',outType:'woff2'}],
|
|
['千字文ttf','天地玄黄宇宙洪荒日月盈昃辰宿列张寒来暑往秋收冬藏闰余成岁律吕调阳云腾致雨露结为霜金生丽水玉出昆冈剑号巨阙珠称夜光果珍李柰菜重芥姜海咸河淡鳞潜羽翔',{sourceType:'ttf',outType:'ttf'}],
|
|
];
|
|
for (const [label,text,opt] of cases) {
|
|
fontSubset(ab, text, opt);
|
|
const N = 300;
|
|
const t0 = performance.now();
|
|
for (let i=0;i<N;i++) fontSubset(ab, text, opt);
|
|
console.log(`${label.padEnd(14)} avg=${((performance.now()-t0)/N).toFixed(3)}ms`);
|
|
}
|