benchmark-derive.mjs 1.0 KB

1234567891011121314151617181920212223242526
  1. import { performance } from 'node:perf_hooks'
  2. // Node ≥22.6 类型剥离直接跑源码:不依赖构建产物,`pnpm build` 是纯类型门禁(dsh 同款:
  3. // tsc 只做聚合类型检查,产物由打包器产出——见 08-22 本地集成踩坑记录 #12)。
  4. import { deriveChapter } from '../packages/core/src/derive/derive.ts'
  5. const facts = Array.from({ length: 200 }, (_, index) => ({
  6. key: { 卷: Math.floor(index / 50) + 1, 章: index + 1, 章名: `章节${index + 1}` },
  7. 窗口就绪: true,
  8. 候选细纲: false,
  9. 确认细纲: index > 0,
  10. 材料包状态: index % 11 === 0 ? '可写' : null,
  11. 有草稿: false,
  12. 唯一待审稿: false,
  13. 有审核记录: false,
  14. 审核完成: false,
  15. 待定稿包完整: false,
  16. 裁决: null,
  17. 已定稿: false,
  18. 需复核标记: [],
  19. }))
  20. const start = performance.now()
  21. let checksum = 0
  22. for (const fact of facts) checksum += deriveChapter(fact).row
  23. const elapsed = performance.now() - start
  24. console.log(JSON.stringify({ chapters: facts.length, elapsedMs: Number(elapsed.toFixed(3)), checksum }))