diff options
Diffstat (limited to 'packages/throughput-store/src/aggregate.ts')
| -rw-r--r-- | packages/throughput-store/src/aggregate.ts | 80 |
1 files changed, 40 insertions, 40 deletions
diff --git a/packages/throughput-store/src/aggregate.ts b/packages/throughput-store/src/aggregate.ts index 2437d9f..28e326a 100644 --- a/packages/throughput-store/src/aggregate.ts +++ b/packages/throughput-store/src/aggregate.ts @@ -12,23 +12,23 @@ */ export interface ThroughputSample { - readonly model: string; - /** Epoch-ms the turn completed. */ - readonly ts: number; - /** Output tokens generated in the turn. */ - readonly outputTokens: number; - /** Pure generation time for the turn (ms), summed across its steps. */ - readonly genMs: number; + readonly model: string; + /** Epoch-ms the turn completed. */ + readonly ts: number; + /** Output tokens generated in the turn. */ + readonly outputTokens: number; + /** Pure generation time for the turn (ms), summed across its steps. */ + readonly genMs: number; } export interface ModelThroughput { - readonly model: string; - /** Token-weighted average tokens/second over the period. */ - readonly tokensPerSecond: number; - readonly totalOutputTokens: number; - readonly totalGenMs: number; - /** Number of turns that contributed. */ - readonly turns: number; + readonly model: string; + /** Token-weighted average tokens/second over the period. */ + readonly tokensPerSecond: number; + readonly totalOutputTokens: number; + readonly totalGenMs: number; + /** Number of turns that contributed. */ + readonly turns: number; } /** @@ -36,37 +36,37 @@ export interface ModelThroughput { * throughput, sorted by tok/s descending (ties broken by model name). */ export function aggregateSamples( - samples: readonly ThroughputSample[], - start: number, - end: number, + samples: readonly ThroughputSample[], + start: number, + end: number, ): ModelThroughput[] { - const byModel = new Map<string, { tokens: number; genMs: number; turns: number }>(); + const byModel = new Map<string, { tokens: number; genMs: number; turns: number }>(); - for (const s of samples) { - if (s.ts < start || s.ts >= end) continue; - const acc = byModel.get(s.model) ?? { tokens: 0, genMs: 0, turns: 0 }; - acc.tokens += s.outputTokens; - acc.genMs += s.genMs; - acc.turns += 1; - byModel.set(s.model, acc); - } + for (const s of samples) { + if (s.ts < start || s.ts >= end) continue; + const acc = byModel.get(s.model) ?? { tokens: 0, genMs: 0, turns: 0 }; + acc.tokens += s.outputTokens; + acc.genMs += s.genMs; + acc.turns += 1; + byModel.set(s.model, acc); + } - const result: ModelThroughput[] = []; - for (const [model, acc] of byModel) { - const tokensPerSecond = acc.genMs > 0 ? round2(acc.tokens / (acc.genMs / 1000)) : 0; - result.push({ - model, - tokensPerSecond, - totalOutputTokens: acc.tokens, - totalGenMs: acc.genMs, - turns: acc.turns, - }); - } + const result: ModelThroughput[] = []; + for (const [model, acc] of byModel) { + const tokensPerSecond = acc.genMs > 0 ? round2(acc.tokens / (acc.genMs / 1000)) : 0; + result.push({ + model, + tokensPerSecond, + totalOutputTokens: acc.tokens, + totalGenMs: acc.genMs, + turns: acc.turns, + }); + } - result.sort((a, b) => b.tokensPerSecond - a.tokensPerSecond || a.model.localeCompare(b.model)); - return result; + result.sort((a, b) => b.tokensPerSecond - a.tokensPerSecond || a.model.localeCompare(b.model)); + return result; } function round2(n: number): number { - return Math.round(n * 100) / 100; + return Math.round(n * 100) / 100; } |
