Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Divide by zero error if totalTime == 0 #58

Closed
spbolton opened this issue Apr 13, 2015 · 2 comments · Fixed by #59
Closed

Divide by zero error if totalTime == 0 #58

spbolton opened this issue Apr 13, 2015 · 2 comments · Fixed by #59

Comments

@spbolton
Copy link
Contributor

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;
        }
@spbolton
Copy link
Contributor Author

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)

@sindresorhus
Copy link
Owner

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

Pull request welcome :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants