import Benchmark from 'benchmark'

const suite = new Benchmark.Suite()

function isEmpty1(obj) {
  for (const prop in obj) {
    if (Object.prototype.hasOwnProperty.call(obj, prop)) {
      return false
    }
  }
  return true
}

function isEmpty2(obj) {
  return Object.getOwnPropertyNames(obj).length === 0
}

suite.add('for ... in', function() {
  isEmpty1({ a: 1, b: 2, c: 3 })
})

suite.add('keys', function() {
  isEmpty2({ a: 1, b: 2, c: 3 })
})

suite.on('abort', function() {
  console.log('Aborted')
})

suite.on('error', function(event) {
  console.log(String(JSON.stringify(event)))
})

suite.on('cycle', function(event) {
  console.log(String(event.target))
})

suite.on('complete', function() {
  console.log('Fastest is ' + this.filter('fastest').map('name'))
})

suite.run()