benchmark.js 572 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
const Benchmark = require('benchmark');
const mime = require('..');
const mimeLite = require('../lite');

const suite = new Benchmark.Suite();

const extensions = Object.keys(mime._types);
let idx = 0;

suite
  .add('mime.getType',
    function() {
      mime.getType(extensions[idx++]);
      if (idx >= extensions.length) idx = 0;
    }
  )
  .add('mimeLite.getType',
    function() {
      mimeLite.getType(extensions[idx++]);
      if (idx >= extensions.length) idx = 0;
    }
  )
  .on('cycle', function(event) {
    console.log(String(event.target));
  })
  .run();