sindresorhus / time-grunt

Display the elapsed execution time of grunt tasks

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Divide by zero error if totalTime == 0

spbolton opened this issue · comments

At (Line 109)[https://github.com/sindresorhus/time-grunt/blob/master/index.js#L109] add isNaN check.

        if (isNaN(avg) ||  (avg < 0.01 && !grunt.option('verbose'))) {
            return;
        }

Issue is caused by time less that about 15ms Date.now() is not more accurate than this and anything quicker will return the same value for the end and start time producing a totalTime of 0. process.hrtime() could be used instead of Date.now() for more accurate timings. NaN causes following error to be displayed.

e:\git\cloud-commons\pom-main-node-parent\node_modules\time-grunt\index.js:103
                    var bar = new Array(barLength).join(barChar);
                              ^
RangeError: Invalid array length
    at createBar (e:\git\cloud-commons\pom-main-node-parent\node_modules\time-grunt\index.js:103:14)

process.hrtime() could be used instead of Date.now() for more accurate timings.

Pull request welcome :)