Skip to content

Commit 48efb08

Browse files
committed
Readme updated.
1 parent dd158a0 commit 48efb08

1 file changed

Lines changed: 78 additions & 3 deletions

File tree

readme.md

Lines changed: 78 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ Requires Node.js 16.11 or later (ES2022).
210210
### Creating a Sparstogram
211211

212212
```ts
213-
import { Sparstogram } from "sparstogram";
213+
import { Sparstogram, Quantile, Marker } from "sparstogram";
214214

215215
// Initialize a Sparstogram with a maximum of 100 centroids and a quantile marker for maintaining the median
216216
const histogram = new Sparstogram(100, [0.5]);
@@ -269,6 +269,15 @@ for (const entry of histogram.descending({ markerIndex: 0 })) {
269269
for (const entry of histogram.ascending({ value: 2.5 })) {
270270
console.log(entry);
271271
}
272+
273+
// Iterate from the 80th percentile forwards
274+
for (const entry of histogram.ascending({ quantile: 0.8 })) {
275+
console.log(entry);
276+
}
277+
278+
// Type the return values
279+
const q: Quantile = histogram.valueAt(2); // rank, centroid, offset, value
280+
const m: Marker = histogram.quantileAt(0.5); // rank, centroid, offset
272281
```
273282

274283
### Analyzing Histogram Peaks
@@ -314,6 +323,69 @@ const maxLoss = histogram.append(...centroids);
314323
console.log(`Max loss from batch: ${maxLoss}`);
315324
```
316325

326+
## Benchmarks
327+
328+
A formal benchmark suite is included using [tinybench](https://github.com/tinylibs/tinybench). Run it with:
329+
330+
```bash
331+
npm run bench
332+
```
333+
334+
This outputs a human-readable table to stderr and machine-readable JSON to stdout. For clean JSON piping in CI:
335+
336+
```bash
337+
node --expose-gc --import tsx src/sparstogram.bench.ts > results.json
338+
```
339+
340+
### Representative Results
341+
342+
Results from a typical run (actual numbers vary by hardware):
343+
344+
#### add() Hot Path (10K values)
345+
346+
| maxCentroids | Avg Latency (ms) | Throughput (ops/s) |
347+
|-------------|------------------|--------------------|
348+
| 50 | ~106 | ~10 |
349+
| 500 | ~158 | ~6 |
350+
| 5000 | ~153 | ~7 |
351+
352+
#### Compression-Heavy add() (5K distinct values)
353+
354+
| maxCentroids | Avg Latency (ms) | Throughput (ops/s) |
355+
|-------------|------------------|--------------------|
356+
| 3 | ~16 | ~63 |
357+
| 5 | ~17 | ~59 |
358+
| 10 | ~18 | ~56 |
359+
360+
#### mergeFrom()
361+
362+
| Source Size | Avg Latency (ms) | Throughput (ops/s) |
363+
|------------|------------------|--------------------|
364+
| 100 | ~1.3 | ~773 |
365+
| 1000 | ~15 | ~65 |
366+
| 5000 | ~69 | ~15 |
367+
368+
#### Bulk Compression
369+
370+
5000 → 50 centroids: ~72ms avg
371+
372+
#### Memory per Centroid
373+
374+
| Centroid Count | Bytes/Centroid |
375+
|---------------|----------------|
376+
| 1000 | ~269 |
377+
| 5000 | ~242 |
378+
| 10000 | ~237 |
379+
380+
### Benchmark Categories (23 entries)
381+
382+
1. **add() hot path** — maxCentroids = 50, 500, 5000; 10K sin(i)*1000 values each
383+
2. **Compression-heavy add()** — maxCentroids = 3, 5, 10; 5K distinct values
384+
3. **Bulk compression** — populate 5000 centroids, then set maxCentroids=50
385+
4. **mergeFrom()** — merge two histograms of N = 100, 1000, 5000 into maxCentroids=100
386+
5. **peaks()** — centroids = 100, 500, 2000; smoothing = 1, 3, 10 (9 combos)
387+
6. **Memory per centroid** — heap delta at centroidCount = 100, 1000, 5000, 10000
388+
317389
## Research and Advanced Topics
318390

319391
### Relationship to Optimal Transport
@@ -583,8 +655,11 @@ Contributions to the Digitree Sparstogram library are welcome! Here's how you ca
583655
### Environment
584656

585657
- If using VSCode use the editorconfig plugin to honor the conventions in `.editorconfig`
586-
- Build: `yarn build` or `npm run build`
587-
- Test: `yarn test` or `npm test`
658+
- Build: `npm run build`
659+
- Test: `npm test`
660+
- Lint: `npm run lint` (ESLint 9 with TypeScript rules)
661+
- Bench: `npm run bench`
662+
- CI: GitHub Actions runs tests and build on push/PR to `master` (Node.js 20 and 22 matrix)
588663

589664
## License
590665

0 commit comments

Comments
 (0)