Skip to content

Commit cd624bf

Browse files
committed
chore: update benchmark
1 parent 81b5c5b commit cd624bf

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

.gitignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@ coverage
99
lib
1010
lib-esm
1111
docs
12-
13-
12+
CPU.*
+14-9
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,46 @@
11
/*
2-
Can be executed using `node -r esm --inspect-brk benchmark/index.js`
2+
Can be executed using `tsx --inspect-brk benchmark/index.js`
3+
Or `tsx --cpu-prof benchmark/index.js`
34
And debug from chrome using `chrome://inspect`
45
*/
56

6-
import { readFileSync } from 'fs';
7-
import { join } from 'path';
7+
import { readFileSync } from 'node:fs';
8+
import { join } from 'node:path';
89

910
import { Matrix } from 'ml-matrix';
1011

11-
import fcnnls from '../src/fcnnls';
12+
import { fcnnls } from '../src/fcnnls';
13+
14+
const __dirname = join(new URL(import.meta.url).pathname, '..');
1215

1316
const concentration = readFileSync(
1417
join(__dirname, '../src/__tests__/data/matrix.txt'),
15-
'utf-8',
18+
'utf8',
1619
);
1720
let linesA = concentration.split(/[\r\n]+/);
1821
let A = [];
1922
for (let line of linesA) {
20-
A.push(line.split(',').map((value) => Number(value)));
23+
A.push(line.split(',').map(Number));
2124
}
2225
let matrix = new Matrix(A);
2326
matrix = matrix.transpose();
2427

2528
const observation = readFileSync(
2629
join(__dirname, '../src/__tests__/data/target.txt'),
27-
'utf-8',
30+
'utf8',
2831
);
2932
let lines = observation.split(/[\r\n]+/);
3033
let b = [];
3134
for (let line of lines) {
32-
b.push(line.split(',').map((value) => Number(value)));
35+
b.push(line.split(',').map(Number));
3336
}
3437
let target = new Matrix(b);
3538
target = target.transpose();
3639

3740
console.profile('start');
3841
console.time('flag');
39-
let result = fcnnls(matrix, target);
42+
for (let i = 0; i < 20; i++) {
43+
let result = fcnnls(matrix, target);
44+
}
4045
console.timeEnd('flag');
4146
console.profileEnd();

0 commit comments

Comments
 (0)