pax_global_header00006660000000000000000000000064130074312310014504gustar00rootroot0000000000000052 comment=fc030888103dff4a22004935ce4d15dd8f34a956 pretty-hrtime-1.0.3/000077500000000000000000000000001300743123100143225ustar00rootroot00000000000000pretty-hrtime-1.0.3/.gitignore000066400000000000000000000001021300743123100163030ustar00rootroot00000000000000.DS_Store *.log node_modules build *.node components *.orig .idea pretty-hrtime-1.0.3/.jshintignore000066400000000000000000000000201300743123100170160ustar00rootroot00000000000000node_modules/** pretty-hrtime-1.0.3/.npmignore000066400000000000000000000001231300743123100163150ustar00rootroot00000000000000.DS_Store *.log node_modules build *.node components *.orig .idea test .travis.yml pretty-hrtime-1.0.3/.travis.yml000066400000000000000000000001211300743123100164250ustar00rootroot00000000000000language: node_js node_js: - "0.10" - "0.12" - "4" - "5" - "6" - "7" pretty-hrtime-1.0.3/LICENSE000066400000000000000000000021131300743123100153240ustar00rootroot00000000000000Copyright (c) 2013 [Richardson & Sons, LLC](http://richardsonandsons.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. pretty-hrtime-1.0.3/README.md000066400000000000000000000041101300743123100155750ustar00rootroot00000000000000[![Build Status](https://secure.travis-ci.org/robrich/pretty-hrtime.png?branch=master)](https://travis-ci.org/robrich/pretty-hrtime) [![Dependency Status](https://david-dm.org/robrich/pretty-hrtime.png)](https://david-dm.org/robrich/pretty-hrtime) pretty-hrtime ============ [process.hrtime()](http://nodejs.org/api/process.html#process_process_hrtime) to words Usage ----- ```javascript var prettyHrtime = require('pretty-hrtime'); var start = process.hrtime(); // do stuff var end = process.hrtime(start); var words = prettyHrtime(end); console.log(words); // '1.2 ms' words = prettyHrtime(end, {verbose:true}); console.log(words); // '1 millisecond 209 microseconds' words = prettyHrtime(end, {precise:true}); console.log(words); // '1.20958 ms' ``` Note: process.hrtime() has been available since 0.7.6. See [http://nodejs.org/changelog.html](http://nodejs.org/changelog.html) and [https://github.com/joyent/node/commit/f06abd](https://github.com/joyent/node/commit/f06abd). LICENSE ------- (MIT License) Copyright (c) 2013 [Richardson & Sons, LLC](http://richardsonandsons.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. pretty-hrtime-1.0.3/index.js000066400000000000000000000043531300743123100157740ustar00rootroot00000000000000/*jshint node:true */ "use strict"; var minimalDesc = ['h', 'min', 's', 'ms', 'μs', 'ns']; var verboseDesc = ['hour', 'minute', 'second', 'millisecond', 'microsecond', 'nanosecond']; var convert = [60*60, 60, 1, 1e6, 1e3, 1]; module.exports = function (source, opts) { var verbose, precise, i, spot, sourceAtStep, valAtStep, decimals, strAtStep, results, totalSeconds; verbose = false; precise = false; if (opts) { verbose = opts.verbose || false; precise = opts.precise || false; } if (!Array.isArray(source) || source.length !== 2) { return ''; } if (typeof source[0] !== 'number' || typeof source[1] !== 'number') { return ''; } // normalize source array due to changes in node v5.4+ if (source[1] < 0) { totalSeconds = source[0] + source[1] / 1e9; source[0] = parseInt(totalSeconds); source[1] = parseFloat((totalSeconds % 1).toPrecision(9)) * 1e9; } results = ''; // foreach unit for (i = 0; i < 6; i++) { spot = i < 3 ? 0 : 1; // grabbing first or second spot in source array sourceAtStep = source[spot]; if (i !== 3 && i !== 0) { sourceAtStep = sourceAtStep % convert[i-1]; // trim off previous portions } if (i === 2) { sourceAtStep += source[1]/1e9; // get partial seconds from other portion of the array } valAtStep = sourceAtStep / convert[i]; // val at this unit if (valAtStep >= 1) { if (verbose) { valAtStep = Math.floor(valAtStep); // deal in whole units, subsequent laps will get the decimal portion } if (!precise) { // don't fling too many decimals decimals = valAtStep >= 10 ? 0 : 2; strAtStep = valAtStep.toFixed(decimals); } else { strAtStep = valAtStep.toString(); } if (strAtStep.indexOf('.') > -1 && strAtStep[strAtStep.length-1] === '0') { strAtStep = strAtStep.replace(/\.?0+$/,''); // remove trailing zeros } if (results) { results += ' '; // append space if we have a previous value } results += strAtStep; // append the value // append units if (verbose) { results += ' '+verboseDesc[i]; if (strAtStep !== '1') { results += 's'; } } else { results += ' '+minimalDesc[i]; } if (!verbose) { break; // verbose gets as many groups as necessary, the rest get only one } } } return results; }; pretty-hrtime-1.0.3/package.json000066400000000000000000000010551300743123100166110ustar00rootroot00000000000000{ "name": "pretty-hrtime", "description": "process.hrtime() to words", "version": "1.0.3", "homepage": "https://github.com/robrich/pretty-hrtime", "repository": "git://github.com/robrich/pretty-hrtime.git", "author": "Rob Richardson (http://robrich.org/)", "main": "./index.js", "keywords": [ "hrtime", "benchmark" ], "devDependencies": { "jshint": "^2.9.4", "mocha": "^3.1.2", "should": "^11.1.1" }, "scripts": { "test": "mocha && jshint ." }, "engines": { "node": ">= 0.8" }, "license": "MIT" } pretty-hrtime-1.0.3/test/000077500000000000000000000000001300743123100153015ustar00rootroot00000000000000pretty-hrtime-1.0.3/test/minimal.js000066400000000000000000000024761300743123100172760ustar00rootroot00000000000000/*jshint node:true */ /*global describe:false, it:false */ "use strict"; var prettyHrtime = require('../'); require('should'); require('mocha'); describe('pretty-hrtime', function() { describe('minimal', function () { var runTest = function (expected, source) { var actual; // Arrange // Act actual = prettyHrtime(source); // Assert actual.should.equal(expected); }; it('1.2m', function() { runTest('1.2 min', [72, 100]); }); it('48s', function() { runTest('48 s', [48, 100]); }); it('1.02s', function() { runTest('1.02 s', [1, 2.02e7]); }); it('840ms', function() { runTest('840 ms', [0, 8.4005e8]); }); it('600ms', function() { runTest('600 ms', [0, 6.004e8]); }); it('200ms', function() { runTest('200 ms', [0, 2.004e8]); }); it('1.2ms', function() { runTest('1.2 ms', [0, 1.2004e6]); }); it('600μs', function() { runTest('600 μs', [0, 600200]); }); it('1.2μs', function() { runTest('1.2 μs', [0, 1204]); }); it('600ns', function() { runTest('600 ns', [0, 600]); }); // Node v5.4+ negative nano values it('31s', function() { runTest('31 s', [31, -97909258]); }); it('2.9s', function() { runTest('2.9 s', [3, -95038258]); }); it('603ms', function() { runTest('603 ms', [1, -396570776]); }); }); }); pretty-hrtime-1.0.3/test/precise.js000066400000000000000000000026061300743123100172750ustar00rootroot00000000000000/*jshint node:true */ /*global describe:false, it:false */ "use strict"; var prettyHrtime = require('../'); require('should'); require('mocha'); describe('pretty-hrtime', function() { describe('precise', function () { var runTest = function (expected, source) { var actual; // Arrange // Act actual = prettyHrtime(source, {precise:true}); // Assert actual.should.equal(expected); }; it('1.2m', function() { runTest('1.2 min', [72, 100]); }); it('48s', function() { runTest('48.0000001 s', [48, 100]); }); it('1.02s', function() { runTest('1.0202 s', [1, 2.02e7]); }); it('840ms', function() { runTest('840.05 ms', [0, 8.4005e8]); }); it('600ms', function() { runTest('600.5 ms', [0, 6.005e8]); }); it('200ms', function() { runTest('200.5 ms', [0, 2.005e8]); }); it('1.2ms', function() { runTest('1.2005 ms', [0, 1.2005e6]); }); it('600μs', function() { runTest('600.2 μs', [0, 600200]); }); it('1.2μs', function() { runTest('1.204 μs', [0, 1204]); }); it('600ns', function() { runTest('600 ns', [0, 600]); }); // Node v5.4+ negative nano values it('31s', function() { runTest('30.902090742 s', [31, -97909258]); }); it('2.9s', function() { runTest('2.9049617420000002 s', [3, -95038258]); }); it('603ms', function() { runTest('603.429224 ms', [1, -396570776]); }); }); }); pretty-hrtime-1.0.3/test/smoke.js000066400000000000000000000012141300743123100167530ustar00rootroot00000000000000/*jshint node:true */ /*global describe:false, it:false */ "use strict"; var prettyHrtime = require('../'); require('should'); require('mocha'); describe('pretty-hrtime', function() { describe('smoke', function () { it('should work', function(done) { var duration, regex, startTime, doneTime, actual, match; // Arrange duration = 100; regex = /^1\d\d ms/; // Act startTime = process.hrtime(); setTimeout(function () { doneTime = process.hrtime(startTime); actual = prettyHrtime(doneTime); // Assert match = regex.test(actual); match.should.equal(true); done(); }, duration); }); }); }); pretty-hrtime-1.0.3/test/verbose.js000066400000000000000000000036251300743123100173120ustar00rootroot00000000000000/*jshint node:true */ /*global describe:false, it:false */ "use strict"; var prettyHrtime = require('../'); require('should'); require('mocha'); describe('pretty-hrtime', function() { describe('verbose', function () { var runTest = function (expected, source) { var actual; // Arrange // Act actual = prettyHrtime(source, {verbose:true}); // Assert actual.should.equal(expected); }; it('1.2h', function() { runTest('1 hour 12 minutes 10 seconds', [4330, 0]); }); it('1.2m', function() { runTest('1 minute 12 seconds 100 nanoseconds', [72, 100]); }); it('1m', function() { runTest('1 minute 100 nanoseconds', [60, 100]); }); it('48s', function() { runTest('48 seconds 100 nanoseconds', [48, 100]); }); it('1.02s', function() { runTest('1 second 20 milliseconds 200 microseconds', [1, 2.02e7]); }); it('840ms', function() { runTest('840 milliseconds 50 microseconds', [0, 8.4005e8]); }); it('600ms', function() { runTest('600 milliseconds 500 microseconds', [0, 6.005e8]); }); it('200ms', function() { runTest('200 milliseconds 500 microseconds', [0, 2.005e8]); }); it('1.2ms', function() { runTest('1 millisecond 200 microseconds 500 nanoseconds', [0, 1.2005e6]); }); it('600μs', function() { runTest('600 microseconds 200 nanoseconds', [0, 600200]); }); it('1.2μs', function() { runTest('1 microsecond 204 nanoseconds', [0, 1204]); }); it('600ns', function() { runTest('600 nanoseconds', [0, 600]); }); // Node v5.4+ negative nano values it('31s', function() { runTest('30 seconds 902 milliseconds 90 microseconds 742 nanoseconds', [31, -97909258]); }); it('2.9s', function() { runTest('2 seconds 904 milliseconds 961 microseconds 742 nanoseconds', [3, -95038258]); }); it('603ms', function() { runTest('603 milliseconds 429 microseconds 224 nanoseconds', [1, -396570776]); }); }); });