Skip to content

Commit 8e99dcc

Browse files
committed
chore: migrate benchmark script to TypeScript
1 parent 3908aa5 commit 8e99dcc

2 files changed

Lines changed: 54 additions & 58 deletions

File tree

benchmark/contour.mjs

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

benchmark/contour.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// node --cpu-prof benchmark/contour.ts
2+
3+
import { readFileSync } from 'node:fs';
4+
import { join } from 'node:path';
5+
6+
import type { NumberMatrix } from 'cheminfo-types';
7+
import { convert } from 'jcampconverter';
8+
9+
import { Conrec } from '../src/index.ts';
10+
11+
const data = readFileSync(
12+
join(import.meta.dirname, '../src/__tests__/data/zhmbc_0.jdx'),
13+
'utf8',
14+
);
15+
const parsed = convert(data, { noContour: true }).flatten[0];
16+
17+
const rawMatrix = parsed.minMax?.z;
18+
if (!rawMatrix) {
19+
throw new Error('Failed to parse matrix from JCAMP file');
20+
}
21+
22+
const matrix: NumberMatrix = rawMatrix.map((row) => Float64Array.from(row));
23+
24+
// eslint-disable-next-line no-console
25+
console.log('Size: ', matrix[0].length, 'x', matrix.length);
26+
27+
const conrec = new Conrec(matrix);
28+
29+
const levels: number[] = [];
30+
for (let level = -1e4; level <= 1e4; level += 2e2) {
31+
levels.push(level);
32+
}
33+
34+
// eslint-disable-next-line no-console
35+
console.log(
36+
`We calculate ${levels.length} levels close to zero to be close to noise`,
37+
);
38+
39+
console.time('basic');
40+
41+
const result = conrec.drawContour({
42+
contourDrawer: 'basic',
43+
levels,
44+
timeout: 100000,
45+
});
46+
// eslint-disable-next-line no-console
47+
console.log(result.contours.length);
48+
console.timeEnd('basic');
49+
const totalNumberContours = result.contours.reduce(
50+
(acc, contour) => acc + contour.lines.length,
51+
0,
52+
);
53+
// eslint-disable-next-line no-console
54+
console.log({ totalNumberContours });

0 commit comments

Comments
 (0)