shownMs

tcmts.cli.main.shownMs · #av4m2ns7 · term · runs anywhere

A span's time, as tcm traces shows it.

export function shownMs(ms: number): string {
  if (ms < 1) return `${ms.toFixed(2)}ms`;
  if (ms < 10) return `${ms.toFixed(1)}ms`;
  if (ms < 1000) return `${Math.round(ms)}ms`;
  return `${(ms / 1000).toFixed(ms < 10_000 ? 2 : 1)}s`;
}

used by