1
1
import { run , bench , lineplot , do_not_optimize } from 'mitata' ;
2
2
import { SparseMatrix } from '../src/index.js' ;
3
- import { randomSparseMatrix } from './utils/randomSparseMatrix.js' ;
4
- import { Matrix } from 'ml-matrix' ;
3
+ import { xSequentialFillFromStep } from 'ml-spectra-processing' ;
5
4
import { SparseMatrix as SparseMatrixOld } from './class/SparseMatrixOld.js' ;
6
5
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
6
+ const density = 0.02 ; // Fixed density for this comparison;
11
7
8
+ // Prepare matrices once
9
+ const sizes = Array . from (
10
+ xSequentialFillFromStep ( { from : 4 , step : 4 , size : 13 } ) ,
11
+ ) ;
12
12
lineplot ( ( ) => {
13
13
bench ( 'Sparse.mmul($size)' , function * ( ctx ) {
14
14
const size = ctx . get ( 'size' ) ;
@@ -18,7 +18,7 @@ lineplot(() => {
18
18
const B = new SparseMatrix ( randomMatrix ( size , size , density ) ) ;
19
19
// Benchmark the multiplication
20
20
yield ( ) => do_not_optimize ( A . mmul ( B ) ) ;
21
- } ) . range ( 'size' , min , max , 2 ) ; // 16, 32, 64, 128, 256
21
+ } ) . args ( 'size' , sizes ) ; // 16, 32, 64, 128, 256
22
22
23
23
bench ( 'SparseOld.mmul($size)' , function * ( ctx ) {
24
24
const size = ctx . get ( 'size' ) ;
@@ -29,20 +29,20 @@ lineplot(() => {
29
29
30
30
// Benchmark the multiplication
31
31
yield ( ) => do_not_optimize ( AOld . mmul ( BOld ) ) ;
32
- } ) . range ( 'size' , min , max , 2 ) ;
32
+ } ) . args ( 'size' , sizes ) ;
33
33
34
- bench ( 'Dense.mmul($size)' , function * ( ctx ) {
35
- const size = ctx . get ( 'size' ) ;
34
+ // bench('Dense.mmul($size)', function* (ctx) {
35
+ // const size = ctx.get('size');
36
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 ) ;
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
42
43
- // Benchmark the multiplication
44
- yield ( ) => do_not_optimize ( ADense . mmul ( BDense ) ) ;
45
- } ) . range ( 'size' , min , max , 2 ) ;
43
+ // // Benchmark the multiplication
44
+ // yield () => do_not_optimize(ADense.mmul(BDense));
45
+ // }).range('size', min, max, multiplier );
46
46
} ) ;
47
47
48
48
await run ( ) ;
0 commit comments