Blame view

node_modules/bfj-node4/test/performance.js 810 Bytes
aaac7fed   liuqimichale   add
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
  #!/usr/bin/env node
  
  'use strict'
  
  const fs = require('fs')
  const path = require('path')
  const check = require('check-types')
  const bfj = require('../src')
  
  console.log('reading json')
  
  let time = process.hrtime()
  
  bfj.read(getDataPath('.json'))
    .then(data => {
      reportTime()
      console.log('writing json')
      return bfj.write(getDataPath('-result.json'), data)
    })
    .then(() => done('succeeded'))
    .catch(error => done(error.stack, 1))
  
  function getDataPath (suffix) {
    return path.resolve(__dirname, process.argv[2] + suffix)
  }
  
  function reportTime () {
    let interimTime = process.hrtime(time)
    console.log('%d seconds and %d nanoseconds', interimTime[0], interimTime[1])
    time = process.hrtime()
  }
  
  function done (message, code) {
    reportTime()
    console.log(message)
    process.exit(code)
  }