Statistics
Simloop includes a built-in statistics collector for tracking numeric metrics during simulation.
Recording Values
sim.on('customer:serve', (event, ctx) => {
ctx.stats.record('serviceTime', ctx.clock - startTime);
ctx.stats.increment('served');
});StatsCollector API
| Method | Description |
|---|---|
stats.record(name, value) | Record a numeric observation |
stats.increment(name, by?) | Increment a counter (default: +1) |
stats.get(name) | Get summary for a named metric |
stats.getAll() | Get all recorded metrics |
stats.reset() | Reset all metrics |
StatsSummary
Each metric provides a StatsSummary with online-computed statistics:
interface StatsSummary {
count: number;
sum: number;
min: number;
max: number;
mean: number;
variance: number;
}Reading Results
const result = sim.run();
const wt = result.stats['waitTime'];
console.log(`Mean wait: ${wt.mean.toFixed(2)}`);
console.log(`Max wait: ${wt.max.toFixed(2)}`);
console.log(`Served: ${result.stats['served'].count}`);Last updated on