Skip to content

Instantly share code, notes, and snippets.

@mattpodwysocki
Created July 1, 2016 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattpodwysocki/fd7943af9d53d36638990391a5be165a to your computer and use it in GitHub Desktop.
Save mattpodwysocki/fd7943af9d53d36638990391a5be165a to your computer and use it in GitHub Desktop.
Using benchmark.js instead of perfy
λ node index.js
normal path time x 556 ops/sec ±9.22% (46 runs sampled)
UNC path time x 398 ops/sec ±10.97% (38 runs sampled)
Fastest is normal path time
'use strict';
const path = require('path')
const fs = require('fs')
const Benchmark = require('benchmark');
const normalPath = path.join(__dirname, 'testfile.txt')
const uncPath = `\\\\?\\${normalPath}`
function readWriteFile(path) {
fs.writeFileSync(path, 'Hello Node.js', 'utf8');
const file = fs.readFileSync(path, { encoding: 'utf8' })
}
var suite = new Benchmark.Suite;
// add tests
suite.add('normal path time', function() {
readWriteFile(normalPath)
})
.add('UNC path time', function() {
readWriteFile(uncPath)
})
// add listeners
.on('cycle', function(event) {
console.log(String(event.target));
})
.on('complete', function() {
console.log('Fastest is ' + this.filter('fastest').map('name'));
})
// run async
.run({ 'async': true });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment