@softsky/utils 1.0.3 → 1.0.4

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/README.md CHANGED
@@ -108,6 +108,8 @@ it will still check them by reference.
108
108
 
109
109
  ## time
110
110
  Timers, CRON, etc.
111
+ ### function measurePerformance
112
+ Measure performance of a function
111
113
  ### function cronInterval
112
114
  Like setInterval but with cron. Returns clear function.
113
115
  ### function getNextCron
package/dist/time.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  /**
2
2
  * Timers, CRON, etc.
3
3
  */
4
+ /** Measure performance of a function */
5
+ export declare function measurePerformance(function_: () => unknown, timeCheck?: number): number;
4
6
  /** Like setInterval but with cron. Returns clear function. */
5
7
  export declare function cronInterval(function_: () => unknown, cronString: string): () => void;
6
8
  /** Find next cron tick after passed date */
package/dist/time.js CHANGED
@@ -3,6 +3,16 @@
3
3
  */
4
4
  import { HOUR_MS } from './consts';
5
5
  import { ValidationError } from './errors';
6
+ /** Measure performance of a function */
7
+ export function measurePerformance(function_, timeCheck = 16.6) {
8
+ const endTime = performance.now() + timeCheck;
9
+ let executions = 0;
10
+ while (performance.now() < endTime) {
11
+ function_();
12
+ executions++;
13
+ }
14
+ return executions;
15
+ }
6
16
  /** Like setInterval but with cron. Returns clear function. */
7
17
  export function cronInterval(function_, cronString) {
8
18
  let timeout;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@softsky/utils",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "JavaScript/TypeScript utilities",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {