performance.js 810 B

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