diff --git a/lib/debug.js b/lib/debug.js index 6d7c333..b1457d6 100644 --- a/lib/debug.js +++ b/lib/debug.js @@ -69,6 +69,25 @@ function color() { return colors[prevColor++ % colors.length]; } +/** + * Humanize the given `ms`. + * + * @param {Number} m + * @return {String} + * @api private + */ + +function humanize(ms) { + var sec = 1000 + , min = 60 * 1000 + , hour = 60 * min; + + if (ms >= hour) return (ms / hour).toFixed(1) + 'h'; + if (ms >= min) return (ms / min).toFixed(1) + 'm'; + if (ms >= sec) return (ms / sec | 0) + 's'; + return ms + 'ms'; +} + /** * Create a debugger with the given `name`. * @@ -93,7 +112,7 @@ function debug(name) { fmt = ' \033[9' + c + 'm' + name + ' ' + '\033[3' + c + 'm\033[90m' + fmt + '\033[3' + c + 'm' - + ' +' + ms + 'ms\033[0m'; + + ' +' + humanize(ms) + '\033[0m'; console.error.apply(this, arguments); }