A node.js module that outputs a progress bar and other metrics to the command-line. It was originally conceived to help measure the 'pace' of long running scripts. We've used it to optimize scripts that would have taken hours to complete down to minutes, without having to wait the hours before knowing that the script could use some optimization.
$ npm install pace
Running the following code:
var total = 50000count = 0pace = total;while count++ < totalpace;// Cause some work to be done.for var i = 0; i < 1000000; i++count = count;
Will cause output to your console similar to:
The module exports a factory function to generate instances of
require('pace')(<options>) creates an instance of
options to the constructor.
Options can either be an object literal, or an integer. If its an integer then
it is the same as passing options with only the
100;// Same astotal: 100;
total- The total number of operations that YOUR script will execute.
maxBurden- The maximum 'burden' that the progress bar should incur. See more about burden below.
showBurden- Mostly for debugging. Show the current burden / skipped steps with the other metrics.
Signal to pace that an operation was completed in your script by calling
If you would rather track the progress in your own logic, you can call
<count> is the current operation interation
(for example step # 50 of a 100 step process).
If your script has a dynamic amount of work to do (for example, depending on the
results of previous operation there may be more steps to complete), you can
freely change the value of pace.total. Just set the value like:
pace.total = 200.
Depending on how intensive your operations are, calculating, formatting, and printing the progress bar might be much more expensive than the work you are doing. It would be silly if printing a progress bar caused your job to take significantly longer than it would have otherwise. Pace tracks a stat called 'burden', which is basically a percentage of the overall execution time that is being spent inside the progress bar logic itself.
0.5, which translates to
0.5% of the total execution time. If this low burden is causing you to see progress reported less
often than you would prefer, you can raise it to something like
20 (20%) via
test/ folder contains some simple test scripts you can run to see the
progress bar in action.
Terra Eclipse, Inc. is a nationally recognized political technology and strategy firm located in Aptos, CA and Washington, D.C.
Copyright (C) 2012 Terra Eclipse, Inc. (http://www.terraeclipse.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.