Created
July 1, 2016 15:53
-
-
Save mattpodwysocki/fd7943af9d53d36638990391a5be165a to your computer and use it in GitHub Desktop.
Using benchmark.js instead of perfy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
λ 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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