Skip to content

Instantly share code, notes, and snippets.

@dhh
Created March 28, 2017 08:37
Show Gist options
  • Save dhh/47497d1d4603b6be002120e1a86ef899 to your computer and use it in GitHub Desktop.
Save dhh/47497d1d4603b6be002120e1a86ef899 to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
// Results from MacBook (Retina, 12-inch, Early 2016), 1.3 GHz Intel Core m7, macOS 10.12.3, Node 7.6.0
// let a = { z: 1 }
// human-friendly x 85,821,153 ops/sec ±1.81% (87 runs sampled)
// machine-friendly x 92,613,579 ops/sec ±1.89% (85 runs sampled)
// Fastest is machine-friendly
// let a = undefined
// human-friendly x 93,950,465 ops/sec ±2.19% (85 runs sampled)
// machine-friendly x 93,779,232 ops/sec ±2.03% (85 runs sampled)
// Fastest is human-friendly,machine-friendly
const Benchmark = require('benchmark')
const suite = new Benchmark.Suite
let a = undefined
suite
.add('human-friendly', function () { if (a) true })
.add('machine-friendly', function () { if (a !== undefined) true })
.on('complete', function () { console.log('Fastest is ' + this.filter('fastest').map('name')) })
.on('cycle', function(event) { console.log(String(event.target)) })
.run()
@esparta
Copy link

esparta commented Mar 28, 2017

# MacBook Pro (Retina, 15-inch, Mid 2015),  2.2 GHz Intel Core i7, macOS 10.10.5

human-friendly x 78,400,466 ops/sec ±1.65% (82 runs sampled)
machine-friendly x 82,932,839 ops/sec ±1.32% (86 runs sampled)
Fastest is machine-friendly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment