mirror of
https://github.com/NotAShelf/nix-evaluator-stats.git
synced 2026-04-29 13:25:21 +00:00
packages/web: allow selecting integer precision in visuals & comparison view
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: Idd4ed0b32ba827254de9c501685d5edb6a6a6964
This commit is contained in:
parent
6ec645f3de
commit
5af2457177
8 changed files with 143 additions and 48 deletions
|
|
@ -1,23 +1,23 @@
|
|||
export function formatBytes(bytes: number): string {
|
||||
export function formatBytes(bytes: number, precision = 2): string {
|
||||
if (bytes === 0) return '0 B';
|
||||
const units = ['B', 'KB', 'MB', 'GB'];
|
||||
const i = Math.floor(Math.log2(bytes) / 10);
|
||||
return `${(bytes / (1 << (i * 10))).toFixed(2)} ${units[i]}`;
|
||||
return `${(bytes / (1 << (i * 10))).toFixed(precision)} ${units[i]}`;
|
||||
}
|
||||
|
||||
export function formatNumber(num: number): string {
|
||||
if (num >= 1e9) return (num / 1e9).toFixed(2) + 'B';
|
||||
if (num >= 1e6) return (num / 1e6).toFixed(2) + 'M';
|
||||
if (num >= 1e3) return (num / 1e3).toFixed(2) + 'K';
|
||||
export function formatNumber(num: number, precision = 2): string {
|
||||
if (num >= 1e9) return (num / 1e9).toFixed(precision) + 'B';
|
||||
if (num >= 1e6) return (num / 1e6).toFixed(precision) + 'M';
|
||||
if (num >= 1e3) return (num / 1e3).toFixed(precision) + 'K';
|
||||
return num.toString();
|
||||
}
|
||||
|
||||
export function formatTime(seconds: number): string {
|
||||
if (seconds < 0.001) return (seconds * 1e6).toFixed(2) + 'μs';
|
||||
if (seconds < 1) return (seconds * 1000).toFixed(2) + 'ms';
|
||||
export function formatTime(seconds: number, precision = 2): string {
|
||||
if (seconds < 0.001) return (seconds * 1e6).toFixed(precision) + 'μs';
|
||||
if (seconds < 1) return (seconds * 1000).toFixed(precision) + 'ms';
|
||||
return seconds.toFixed(3) + 's';
|
||||
}
|
||||
|
||||
export function formatPercent(value: number): string {
|
||||
return (value * 100).toFixed(2) + '%';
|
||||
export function formatPercent(value: number, precision = 2): string {
|
||||
return (value * 100).toFixed(precision) + '%';
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue