@universal-packages/time-measurer 1.2.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +9 -0
- package/Measurement.d.ts +3 -3
- package/Measurement.js +4 -4
- package/Measurement.js.map +1 -1
- package/README.md +6 -11
- package/TimeMeasurer.d.ts +3 -3
- package/TimeMeasurer.js +4 -4
- package/TimeMeasurer.js.map +1 -1
- package/index.d.ts +1 -1
- package/index.js +2 -2
- package/index.js.map +1 -1
- package/package.json +3 -2
package/LICENSE.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022-present David De Anda
|
4
|
+
|
5
|
+
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:
|
6
|
+
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
8
|
+
|
9
|
+
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.
|
package/Measurement.d.ts
CHANGED
@@ -5,11 +5,11 @@ export default class Measurement {
|
|
5
5
|
readonly seconds: number;
|
6
6
|
readonly milliseconds: number;
|
7
7
|
constructor(nanoseconds: bigint);
|
8
|
-
/** Returns the measured time in a
|
8
|
+
/** Returns the measured time in a formatted string */
|
9
9
|
toString(format?: TimeFormat): string;
|
10
|
-
/** Returns the measured time in a
|
10
|
+
/** Returns the measured time in a formatted string */
|
11
11
|
toDate(): Date;
|
12
|
-
private
|
12
|
+
private getCondensed;
|
13
13
|
private getHuman;
|
14
14
|
private gerExpressive;
|
15
15
|
private pad;
|
package/Measurement.js
CHANGED
@@ -11,22 +11,22 @@ class Measurement {
|
|
11
11
|
currentNanoseconds = currentNanoseconds - BigInt(Math.floor(this.seconds)) * 1000000000n;
|
12
12
|
this.milliseconds = Number(currentNanoseconds) / 1000000;
|
13
13
|
}
|
14
|
-
/** Returns the measured time in a
|
14
|
+
/** Returns the measured time in a formatted string */
|
15
15
|
toString(format = 'Human') {
|
16
16
|
switch (format) {
|
17
17
|
case 'Condensed':
|
18
|
-
return this.
|
18
|
+
return this.getCondensed();
|
19
19
|
case 'Human':
|
20
20
|
return this.getHuman();
|
21
21
|
case 'Expressive':
|
22
22
|
return this.gerExpressive();
|
23
23
|
}
|
24
24
|
}
|
25
|
-
/** Returns the measured time in a
|
25
|
+
/** Returns the measured time in a formatted string */
|
26
26
|
toDate() {
|
27
27
|
return new Date(0, 0, 0, this.hours, this.minutes, this.seconds, this.milliseconds);
|
28
28
|
}
|
29
|
-
|
29
|
+
getCondensed() {
|
30
30
|
if (this.hours !== 0) {
|
31
31
|
return `${this.pad(this.hours)}:${this.pad(this.minutes)}:${this.pad(this.seconds)}.${this.pad(this.milliseconds, 3)}`;
|
32
32
|
}
|
package/Measurement.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Measurement.js","sourceRoot":"","sources":["../src/Measurement.ts"],"names":[],"mappings":";;AAEA,MAAqB,WAAW;IAM9B,YAAmB,WAAmB;QACpC,IAAI,kBAAkB,GAAG,WAAW,CAAA;QAEpC,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,kBAAkB,GAAG,cAAc,CAAC,CAAA;QACxD,kBAAkB,GAAG,kBA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SACrH;aAAM,IAAI,IAAI,CAAC,OAAO,KAAK,CAAC,EAAE;YAC7B,OAAO,GAAG,IAAI,CAAC,OAAO,iBAAiB,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC,CAAC,UAAU,CAAA;SAChG;aAAM,IAAI,IAAI,CAAC,OAAO,KAAK,CAAC,EAAE;YAC7B,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC,CAAC,UAAU,CAAA;SACnE;aAAM;YACL,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC,EAAE,CAAC,CAAC,eAAe,CAAA;SAC3D;IACH,CAAC;IAEO,GAAG,CAAC,GAAW,EAAE,MAAM,GAAG,CAAC,EAAE,YAAY,GAAG,CAAC;QACnD,OAAO,GAAG,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACxD,CAAC;CACF;AA7ED,8BA6EC"}
|
package/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# Time Measurer
|
2
|
+
|
2
3
|
[](https://www.npmjs.com/package/@universal-packages/time-measurer)
|
3
4
|
[](https://github.com/universal-packages/universal-time-measurer/actions/workflows/testing.yml)
|
4
5
|
[](https://codecov.io/gh/universal-packages/universal-time-measurer)
|
@@ -13,7 +14,7 @@ npm install @universal-packages/time-measurer
|
|
13
14
|
|
14
15
|
## startMeasurement()
|
15
16
|
|
16
|
-
Creates a new TimeMeasurer instance to start a
|
17
|
+
Creates a new TimeMeasurer instance to start a measurement.
|
17
18
|
|
18
19
|
```ts
|
19
20
|
import { startMeasurement } from '@universal-packages/time-measurer'
|
@@ -26,7 +27,6 @@ async function getAll() {
|
|
26
27
|
console.log('All records - ', measurement.toString())
|
27
28
|
}
|
28
29
|
|
29
|
-
|
30
30
|
getAll()
|
31
31
|
// > All records - 2.23ms
|
32
32
|
```
|
@@ -36,7 +36,7 @@ getAll()
|
|
36
36
|
Class `TimeMeasurer` provides an instantiable interface to start measuring time from any part of your code. The measurement starts at instancing time.
|
37
37
|
|
38
38
|
```js
|
39
|
-
import TimeMeasurer from '@universal-packages/time-measurer'
|
39
|
+
import { TimeMeasurer } from '@universal-packages/time-measurer'
|
40
40
|
|
41
41
|
async function getAll() {
|
42
42
|
const measurer = new TimeMeasurer()
|
@@ -66,7 +66,7 @@ measurement.toString('Human')
|
|
66
66
|
measurement.toString('Expressive')
|
67
67
|
```
|
68
68
|
|
69
|
-
You will get
|
69
|
+
You will get something like
|
70
70
|
|
71
71
|
```
|
72
72
|
2hrs 35min 51.235sec
|
@@ -96,16 +96,12 @@ measurement.toDate()
|
|
96
96
|
|
97
97
|
Time measurer ships with a convenient sleep function that takes a single parameter `time` in milliseconds, internally it is just a promise with a timeout that resolves it.
|
98
98
|
|
99
|
-
|
100
99
|
```js
|
101
|
-
import
|
100
|
+
import { sleep } from '@universal-packages/time-measurer'
|
102
101
|
|
103
102
|
async function waitable() {
|
104
|
-
|
105
|
-
|
106
|
-
sleep(2000)
|
103
|
+
await sleep(2000)
|
107
104
|
}
|
108
|
-
|
109
105
|
```
|
110
106
|
|
111
107
|
## Typescript
|
@@ -122,4 +118,3 @@ The development of this library happens in the open on GitHub, and we are gratef
|
|
122
118
|
### License
|
123
119
|
|
124
120
|
[MIT licensed](./LICENSE).
|
125
|
-
|
package/TimeMeasurer.d.ts
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
import Measurement from './Measurement';
|
2
2
|
/**
|
3
3
|
*
|
4
|
-
* It
|
4
|
+
* It measures the time a process takes from the time start is called
|
5
5
|
* to when the finish method is called
|
6
6
|
*
|
7
7
|
*/
|
8
8
|
export default class TimeMeasurer {
|
9
|
-
private
|
9
|
+
private hrStart;
|
10
10
|
constructor();
|
11
|
-
/** Returns a measurement representing the time passed from when start
|
11
|
+
/** Returns a measurement representing the time passed from when start was called */
|
12
12
|
finish(): Measurement;
|
13
13
|
}
|
package/TimeMeasurer.js
CHANGED
@@ -6,17 +6,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const Measurement_1 = __importDefault(require("./Measurement"));
|
7
7
|
/**
|
8
8
|
*
|
9
|
-
* It
|
9
|
+
* It measures the time a process takes from the time start is called
|
10
10
|
* to when the finish method is called
|
11
11
|
*
|
12
12
|
*/
|
13
13
|
class TimeMeasurer {
|
14
14
|
constructor() {
|
15
|
-
this.
|
15
|
+
this.hrStart = process.hrtime.bigint();
|
16
16
|
}
|
17
|
-
/** Returns a measurement representing the time passed from when start
|
17
|
+
/** Returns a measurement representing the time passed from when start was called */
|
18
18
|
finish() {
|
19
|
-
const nanoseconds = process.hrtime.bigint() - this.
|
19
|
+
const nanoseconds = process.hrtime.bigint() - this.hrStart;
|
20
20
|
return new Measurement_1.default(nanoseconds);
|
21
21
|
}
|
22
22
|
}
|
package/TimeMeasurer.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"TimeMeasurer.js","sourceRoot":"","sources":["../src/TimeMeasurer.ts"],"names":[],"mappings":";;;;;AAAA,gEAAuC;AAEvC;;;;;GAKG;AACH,MAAqB,YAAY;IAG/B;QACE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,CAAA;IACxC,CAAC;IAED,
|
1
|
+
{"version":3,"file":"TimeMeasurer.js","sourceRoot":"","sources":["../src/TimeMeasurer.ts"],"names":[],"mappings":";;;;;AAAA,gEAAuC;AAEvC;;;;;GAKG;AACH,MAAqB,YAAY;IAG/B;QACE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,CAAA;IACxC,CAAC;IAED,oFAAoF;IAC7E,MAAM;QACX,MAAM,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,OAAO,CAAA;QAE1D,OAAO,IAAI,qBAAW,CAAC,WAAW,CAAC,CAAA;IACrC,CAAC;CACF;AAbD,+BAaC"}
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
@@ -17,9 +17,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
18
18
|
};
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
20
|
-
exports.sleep = exports.Measurement = exports.
|
20
|
+
exports.sleep = exports.Measurement = exports.TimeMeasurer = void 0;
|
21
21
|
var TimeMeasurer_1 = require("./TimeMeasurer");
|
22
|
-
Object.defineProperty(exports, "
|
22
|
+
Object.defineProperty(exports, "TimeMeasurer", { enumerable: true, get: function () { return __importDefault(TimeMeasurer_1).default; } });
|
23
23
|
var Measurement_1 = require("./Measurement");
|
24
24
|
Object.defineProperty(exports, "Measurement", { enumerable: true, get: function () { return __importDefault(Measurement_1).default; } });
|
25
25
|
__exportStar(require("./Measurement.types"), exports);
|
package/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,+
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,+CAAwD;AAA/C,6HAAA,OAAO,OAAgB;AAChC,6CAAsD;AAA7C,2HAAA,OAAO,OAAe;AAC/B,sDAAmC;AACnC,iCAA0C;AAAjC,+GAAA,OAAO,OAAS;AACzB,qDAAkC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@universal-packages/time-measurer",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.3.1",
|
4
4
|
"description": "Utility to measure routines times with precision",
|
5
5
|
"author": "David De Anda <david@universal-packages.com> (https://github.com/universal-packages)",
|
6
6
|
"license": "MIT",
|
@@ -10,7 +10,8 @@
|
|
10
10
|
"scripts": {
|
11
11
|
"build": "tsc --p tsconfig.dis.json",
|
12
12
|
"test": "jest --watch",
|
13
|
-
"test:full": "jest --coverage --verbose"
|
13
|
+
"test:full": "jest --coverage --verbose",
|
14
|
+
"test:clear": "jest --clearCache"
|
14
15
|
},
|
15
16
|
"dependencies": {},
|
16
17
|
"devDependencies": {
|