1'use strict' 2var log = require('npmlog') 3var EventEmitter = require('events').EventEmitter 4var perf = new EventEmitter() 5module.exports = perf 6 7var timings = {} 8 9process.on('time', time) 10process.on('timeEnd', timeEnd) 11 12perf.on('time', time) 13perf.on('timeEnd', timeEnd) 14 15function time (name) { 16 timings[name] = Date.now() 17} 18 19function timeEnd (name) { 20 if (name in timings) { 21 perf.emit('timing', name, Date.now() - timings[name]) 22 delete timings[name] 23 } else { 24 log.silly('timing', "Tried to end timer that doesn't exist:", name) 25 } 26} 27