Skip to content

Commit 44b9822

Browse files
committed
chore: use mitota
1 parent c050090 commit 44b9822

14 files changed

+118
-394
lines changed

benchmark/benchmark.js

Lines changed: 0 additions & 125 deletions
This file was deleted.

benchmark/benchmarkLinePlot.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { run, bench, lineplot, do_not_optimize } from 'mitata';
2+
import { SparseMatrix } from '../src/index.js';
3+
import { randomSparseMatrix } from './utils/randomSparseMatrix.js';
4+
import { Matrix } from 'ml-matrix';
5+
import { SparseMatrix as SparseMatrixOld } from './class/SparseMatrixOld.js';
6+
import { randomMatrix } from './utils/randomMatrix.js';
7+
const density = 0.01; // Fixed density for this comparison;
8+
const min = 32;
9+
const max = 128;
10+
// Prepare matrices once
11+
12+
lineplot(() => {
13+
bench('Sparse.mmul($size)', function* (ctx) {
14+
const size = ctx.get('size');
15+
16+
// Prepare matrices once
17+
const A = new SparseMatrix(randomMatrix(size, size, density));
18+
const B = new SparseMatrix(randomMatrix(size, size, density));
19+
// Benchmark the multiplication
20+
yield () => do_not_optimize(A.mmul(B));
21+
}).range('size', min, max, 2); // 16, 32, 64, 128, 256
22+
23+
bench('SparseOld.mmul($size)', function* (ctx) {
24+
const size = ctx.get('size');
25+
const A = randomMatrix(size, size, density);
26+
const B = randomMatrix(size, size, density);
27+
const AOld = new SparseMatrixOld(A);
28+
const BOld = new SparseMatrixOld(B);
29+
30+
// Benchmark the multiplication
31+
yield () => do_not_optimize(AOld.mmul(BOld));
32+
}).range('size', min, max, 2);
33+
34+
bench('Dense.mmul($size)', function* (ctx) {
35+
const size = ctx.get('size');
36+
37+
// Prepare matrices once
38+
const A = randomMatrix(size, size, density);
39+
const B = randomMatrix(size, size, density);
40+
const ADense = new Matrix(A);
41+
const BDense = new Matrix(B);
42+
43+
// Benchmark the multiplication
44+
yield () => do_not_optimize(ADense.mmul(BDense));
45+
}).range('size', min, max, 2);
46+
});
47+
48+
await run();

benchmark/benchmarkMitata.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { run, bench, group, do_not_optimize } from 'mitata';
2+
import { Matrix } from 'ml-matrix';
3+
import { SparseMatrix as SparseMatrixOld } from './class/SparseMatrixOld2.js';
4+
import fs from 'fs';
5+
import { randomSparseMatrix } from './utils/randomSparseMatrix.js';
6+
7+
const sizes = [64, 128, 256];
8+
const densities = [0.01, 0.015, 0.02, 0.025, 0.03];
9+
const results = [];
10+
11+
for (const density of densities) {
12+
for (const size of sizes) {
13+
const A = randomSparseMatrix(size, size, density);
14+
const B = randomSparseMatrix(size, size, density);
15+
let denseA = A.to2DArray();
16+
let denseB = B.to2DArray();
17+
const AOld = new SparseMatrixOld(denseA);
18+
const BOld = new SparseMatrixOld(denseB);
19+
denseA = new Matrix(denseA);
20+
denseB = new Matrix(denseB);
21+
22+
// Warm up
23+
A.mmul(B);
24+
25+
let mmulNewAvg, mmulAvg, denseAvg;
26+
27+
group(`size:${size}-density:${density}`, () => {
28+
bench('mmulNew', () => {
29+
do_not_optimize(A.mmul(B));
30+
}); //.gc('inner');
31+
bench('mmul', () => {
32+
do_not_optimize(AOld.mmul(BOld));
33+
}); //.gc('inner');
34+
bench('denseMatrix', () => {
35+
do_not_optimize(denseA.mmul(denseB));
36+
}); //.gc('inner');
37+
});
38+
39+
// mitata will handle timing and reporting
40+
// You can extract results from mitata's output or use the save() function
41+
}
42+
}
43+
44+
await run({ silent: false });
45+
// await save({ file: './benchmark/mitata_results.json', format: 'json' });

benchmark/class/SparseMatrixOld.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1383,4 +1383,4 @@ export class SparseMatrix {
13831383
SparseMatrix.prototype.klass = 'Matrix';
13841384

13851385
SparseMatrix.identity = SparseMatrix.eye;
1386-
SparseMatrix.prototype.tensorProduct = SparseMatrix.prototype.kroneckerProduct;
1386+
SparseMatrix.prototype.tensorProduct = SparseMatrix.prototype.kroneckerProduct;

benchmark/denseMatrix.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

benchmark/sparseMatrix.byhand.js

Lines changed: 0 additions & 41 deletions
This file was deleted.

benchmark/sparseMatrix.js

Lines changed: 0 additions & 30 deletions
This file was deleted.

benchmark/squareMatrixBenchmark.js

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)