source: frontend/node_modules/bfj/test/performance.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 13 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.4 KB
Line 
1#!/usr/bin/env node
2
3'use strict'
4
5const fs = require('fs')
6const path = require('path')
7const check = require('check-types')
8const bfj = require('../src')
9
10const inPath = getDataPath('.json');
11
12let time = process.hrtime()
13
14if (process.argv.length === 4) {
15 const stuff = []
16 const stream = bfj.match(fs.createReadStream(inPath), process.argv[3])
17 stream.on('data', thing => stuff.push(thing))
18 stream.on('end', () => {
19 reportTime()
20 console.log('hooray!', stuff.length)
21 fs.writeFileSync(getDataPath('-result.ndjson'), stuff.map(s => JSON.stringify(s)).join('\n'), {
22 encoding: 'utf8',
23 })
24 process.exit(0)
25 })
26 stream.on('error', error => {
27 console.error('error!', error.stack)
28 process.exit(1)
29 })
30 stream.on('dataError', error => {
31 console.error('dataError!', error.stack)
32 process.exit(2)
33 })
34} else {
35 console.log('reading json')
36 bfj.read(inPath)
37 .then(data => {
38 reportTime()
39 console.log('writing json')
40 return bfj.write(getDataPath('-result.json'), data)
41 })
42 .then(() => done('succeeded'))
43 .catch(error => done(error.stack, 1))
44}
45
46function getDataPath (suffix) {
47 return path.resolve(__dirname, process.argv[2] + suffix)
48}
49
50function reportTime () {
51 let interimTime = process.hrtime(time)
52 console.log('%d seconds and %d nanoseconds', interimTime[0], interimTime[1])
53 time = process.hrtime()
54}
55
56function done (message, code) {
57 reportTime()
58 console.log(message)
59 process.exit(code)
60}
61
Note: See TracBrowser for help on using the repository browser.