Skip to content

Commit e9c54a8

Browse files
committed
Add profiling script
1 parent cd39a32 commit e9c54a8

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

benchmark/profile-cpu.mjs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { TabixIndexedFile } from './esm/index.js'
2+
import { fileURLToPath } from 'url'
3+
import { dirname, join } from 'path'
4+
import inspector from 'inspector'
5+
import fs from 'fs'
6+
7+
const __dirname = dirname(fileURLToPath(import.meta.url))
8+
9+
async function runBenchmark() {
10+
const f = new TabixIndexedFile({
11+
path: join(__dirname, 'test/data/1kg.chr1.subset.vcf.gz'),
12+
})
13+
14+
let totalLines = 0
15+
const iterations = 100
16+
17+
const session = new inspector.Session()
18+
session.connect()
19+
20+
session.post('Profiler.enable', () => {
21+
session.post('Profiler.start', async () => {
22+
for (let iter = 0; iter < iterations; iter++) {
23+
let count = 0
24+
await f.getLines('chr1', 10109, 11000, () => {
25+
count++
26+
})
27+
totalLines += count
28+
}
29+
30+
console.log(`Total lines processed: ${totalLines}`)
31+
32+
session.post('Profiler.stop', (err, { profile }) => {
33+
if (!err) {
34+
fs.writeFileSync('profile.cpuprofile', JSON.stringify(profile))
35+
console.log('CPU profile written to profile.cpuprofile')
36+
console.log('View with: npx speedscope profile.cpuprofile')
37+
}
38+
session.disconnect()
39+
})
40+
})
41+
})
42+
}
43+
44+
runBenchmark().catch(console.error)

0 commit comments

Comments
 (0)