UNPKG

729 BJavaScriptView Raw
1// spin - spin to analyze memory consumption
2//
3// $ node --trace-gc spin.js
4
5const fs = require('fs')
6const path = require('path')
7const pickup = require('../')
8const stream = require('readable-stream')
9
10const here = path.dirname(module.filename)
11const dir = path.join(here, '..', 'test', 'data')
12const all = fs.readdirSync(dir)
13const xml = all.filter((p) => { return path.extname(p) === '.xml' })
14const paths = xml.map((p) => { return path.join(dir, p) })
15
16function rnd (paths) {
17 return paths[Math.floor(Math.random() * paths.length)]
18}
19function parse (p) {
20 const reader = fs.createReadStream(p)
21 const writer = new stream.PassThrough()
22 reader.pipe(pickup()).pipe(writer)
23}
24
25setInterval(() => { parse(rnd(paths)) }, 10)