|
1 | 1 | /*
|
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` |
3 | 4 | And debug from chrome using `chrome://inspect`
|
4 | 5 | */
|
5 | 6 |
|
6 |
| -import { readFileSync } from 'fs'; |
7 |
| -import { join } from 'path'; |
| 7 | +import { readFileSync } from 'node:fs'; |
| 8 | +import { join } from 'node:path'; |
8 | 9 |
|
9 | 10 | import { Matrix } from 'ml-matrix';
|
10 | 11 |
|
11 |
| -import fcnnls from '../src/fcnnls'; |
| 12 | +import { fcnnls } from '../src/fcnnls'; |
| 13 | + |
| 14 | +const __dirname = join(new URL(import.meta.url).pathname, '..'); |
12 | 15 |
|
13 | 16 | const concentration = readFileSync(
|
14 | 17 | join(__dirname, '../src/__tests__/data/matrix.txt'),
|
15 |
| - 'utf-8', |
| 18 | + 'utf8', |
16 | 19 | );
|
17 | 20 | let linesA = concentration.split(/[\r\n]+/);
|
18 | 21 | let A = [];
|
19 | 22 | for (let line of linesA) {
|
20 |
| - A.push(line.split(',').map((value) => Number(value))); |
| 23 | + A.push(line.split(',').map(Number)); |
21 | 24 | }
|
22 | 25 | let matrix = new Matrix(A);
|
23 | 26 | matrix = matrix.transpose();
|
24 | 27 |
|
25 | 28 | const observation = readFileSync(
|
26 | 29 | join(__dirname, '../src/__tests__/data/target.txt'),
|
27 |
| - 'utf-8', |
| 30 | + 'utf8', |
28 | 31 | );
|
29 | 32 | let lines = observation.split(/[\r\n]+/);
|
30 | 33 | let b = [];
|
31 | 34 | for (let line of lines) {
|
32 |
| - b.push(line.split(',').map((value) => Number(value))); |
| 35 | + b.push(line.split(',').map(Number)); |
33 | 36 | }
|
34 | 37 | let target = new Matrix(b);
|
35 | 38 | target = target.transpose();
|
36 | 39 |
|
37 | 40 | console.profile('start');
|
38 | 41 | console.time('flag');
|
39 |
| -let result = fcnnls(matrix, target); |
| 42 | +for (let i = 0; i < 20; i++) { |
| 43 | + let result = fcnnls(matrix, target); |
| 44 | +} |
40 | 45 | console.timeEnd('flag');
|
41 | 46 | console.profileEnd();
|
0 commit comments