@putout/formatter-memory 3.1.0 → 3.1.2

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.
Files changed (2) hide show
  1. package/lib/memory.js +10 -8
  2. package/package.json +1 -1
package/lib/memory.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import {Writable} from 'stream';
2
+ import {hrtime} from 'process';
2
3
 
3
4
  import dump from '@putout/formatter-dump';
4
5
  import cliProgress from 'cli-progress';
@@ -7,9 +8,8 @@ import once from 'once';
7
8
  import format from 'format-io';
8
9
  import montag from 'montag';
9
10
 
10
- import {hrtime} from 'node:process';
11
-
12
- const start = hrtime.bigint();
11
+ const start = once(() => hrtime.bigint());
12
+ const end = once(() => hrtime.bigint());
13
13
 
14
14
  const OK = '👌';
15
15
  const {
@@ -27,6 +27,8 @@ const {
27
27
  } = process.env;
28
28
 
29
29
  export default ({name, options, places, index, count, filesCount, errorsCount}) => {
30
+ start();
31
+
30
32
  const {
31
33
  color = '#ea4336',
32
34
  minCount = 0,
@@ -126,17 +128,17 @@ function getInfo(memory) {
126
128
  return montag`
127
129
  heap used: ${green(heapUsed)}
128
130
  heap total: ${yellow(heapTotal)}
129
- rss: ${red(rss)},
131
+ rss: ${red(rss)}
130
132
  time: ${blueBright(calcTime())}
131
-
132
133
  `;
133
134
  }
134
135
 
136
+ export const maybeZero = (a) => a <= 9 ? '0' : '';
137
+
135
138
  function calcTime() {
136
- const end = hrtime.bigint();
137
- const time = Math.round(Number(end - start) / 1e9);
139
+ const time = Math.round(Number(end() - start()) / 1e9);
138
140
  const minutes = Math.floor(time / 60);
139
141
  const seconds = time % 60;
140
142
 
141
- return `0${minutes}:${seconds <= 9 ? '0' : ''}${seconds}`;
143
+ return `${maybeZero(minutes)}${minutes}:${maybeZero(seconds)}${seconds}`;
142
144
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/formatter-memory",
3
- "version": "3.1.0",
3
+ "version": "3.1.2",
4
4
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
5
5
  "description": "🐊Putout formatter shows memory usage",
6
6
  "homepage": "https://github.com/coderaiser/putout/tree/master/packages/formatter-memory#readme",