@oino-ts/common 0.9.0 → 0.9.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.
@@ -91,7 +91,7 @@ exports.OINOBenchmark = OINOBenchmark;
91
91
  /**
92
92
  * OINOMemoryBenchmark is a memory-based benchmark implementation.
93
93
  * It stores the benchmark data in memory and allows to reset, start, end and get benchmark data.
94
- *
94
+ * In case of recursively/iteratively starting a benchmark, it will honor the first start and ignore the rest. *
95
95
  */
96
96
  class OINOMemoryBenchmark extends OINOBenchmark {
97
97
  _benchmarkCount = {};
@@ -113,7 +113,7 @@ class OINOMemoryBenchmark extends OINOBenchmark {
113
113
  */
114
114
  _start(module, method) {
115
115
  const name = module + "." + method;
116
- if (OINOBenchmark._enabled[module]) {
116
+ if (OINOBenchmark._enabled[module] && ((this._benchmarkStart[name] === undefined) || (this._benchmarkStart[name] === 0))) { // if benchmark is already started (e.g. loop/recursion), do not start it again
117
117
  if (this._benchmarkCount[name] == undefined) {
118
118
  this._benchmarkCount[name] = 0;
119
119
  this._benchmarkData[name] = 0;
@@ -145,6 +145,7 @@ class OINOMemoryBenchmark extends OINOBenchmark {
145
145
  this._benchmarkData[category_name] += duration;
146
146
  }
147
147
  result = this._benchmarkData[name] / this._benchmarkCount[name];
148
+ this._benchmarkStart[name] = 0;
148
149
  }
149
150
  return result;
150
151
  }
@@ -87,7 +87,7 @@ export class OINOBenchmark {
87
87
  /**
88
88
  * OINOMemoryBenchmark is a memory-based benchmark implementation.
89
89
  * It stores the benchmark data in memory and allows to reset, start, end and get benchmark data.
90
- *
90
+ * In case of recursively/iteratively starting a benchmark, it will honor the first start and ignore the rest. *
91
91
  */
92
92
  export class OINOMemoryBenchmark extends OINOBenchmark {
93
93
  _benchmarkCount = {};
@@ -109,7 +109,7 @@ export class OINOMemoryBenchmark extends OINOBenchmark {
109
109
  */
110
110
  _start(module, method) {
111
111
  const name = module + "." + method;
112
- if (OINOBenchmark._enabled[module]) {
112
+ if (OINOBenchmark._enabled[module] && ((this._benchmarkStart[name] === undefined) || (this._benchmarkStart[name] === 0))) { // if benchmark is already started (e.g. loop/recursion), do not start it again
113
113
  if (this._benchmarkCount[name] == undefined) {
114
114
  this._benchmarkCount[name] = 0;
115
115
  this._benchmarkData[name] = 0;
@@ -141,6 +141,7 @@ export class OINOMemoryBenchmark extends OINOBenchmark {
141
141
  this._benchmarkData[category_name] += duration;
142
142
  }
143
143
  result = this._benchmarkData[name] / this._benchmarkCount[name];
144
+ this._benchmarkStart[name] = 0;
144
145
  }
145
146
  return result;
146
147
  }
@@ -66,12 +66,12 @@ export declare abstract class OINOBenchmark {
66
66
  /**
67
67
  * OINOMemoryBenchmark is a memory-based benchmark implementation.
68
68
  * It stores the benchmark data in memory and allows to reset, start, end and get benchmark data.
69
- *
69
+ * In case of recursively/iteratively starting a benchmark, it will honor the first start and ignore the rest. *
70
70
  */
71
71
  export declare class OINOMemoryBenchmark extends OINOBenchmark {
72
- private _benchmarkCount;
73
- private _benchmarkData;
74
- private _benchmarkStart;
72
+ protected _benchmarkCount: Record<string, number>;
73
+ protected _benchmarkData: Record<string, number>;
74
+ protected _benchmarkStart: Record<string, number>;
75
75
  /**
76
76
  * Reset benchmark data (but not what is enabled).
77
77
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oino-ts/common",
3
- "version": "0.9.0",
3
+ "version": "0.9.1",
4
4
  "description": "OINO TS package for common classes.",
5
5
  "author": "Matias Kiviniemi (pragmatta)",
6
6
  "license": "MPL-2.0",
@@ -19,7 +19,7 @@
19
19
  "dependencies": {
20
20
  },
21
21
  "devDependencies": {
22
- "@oino-ts/types": "0.9.0"
22
+ "@oino-ts/types": "0.9.1"
23
23
  },
24
24
  "files": [
25
25
  "src/*.ts",
@@ -104,13 +104,13 @@ export abstract class OINOBenchmark {
104
104
  /**
105
105
  * OINOMemoryBenchmark is a memory-based benchmark implementation.
106
106
  * It stores the benchmark data in memory and allows to reset, start, end and get benchmark data.
107
- *
107
+ * In case of recursively/iteratively starting a benchmark, it will honor the first start and ignore the rest. *
108
108
  */
109
109
  export class OINOMemoryBenchmark extends OINOBenchmark {
110
110
 
111
- private _benchmarkCount:Record<string, number> = {}
112
- private _benchmarkData:Record<string, number> = {}
113
- private _benchmarkStart:Record<string, number> = {}
111
+ protected _benchmarkCount:Record<string, number> = {}
112
+ protected _benchmarkData:Record<string, number> = {}
113
+ protected _benchmarkStart:Record<string, number> = {}
114
114
 
115
115
  /**
116
116
  * Reset benchmark data (but not what is enabled).
@@ -129,7 +129,7 @@ export class OINOMemoryBenchmark extends OINOBenchmark {
129
129
  */
130
130
  protected _start(module:string, method:string):void {
131
131
  const name:string = module + "." + method
132
- if (OINOBenchmark._enabled[module]) {
132
+ if (OINOBenchmark._enabled[module] && ((this._benchmarkStart[name] === undefined) || (this._benchmarkStart[name] === 0))) { // if benchmark is already started (e.g. loop/recursion), do not start it again
133
133
  if (this._benchmarkCount[name] == undefined) {
134
134
  this._benchmarkCount[name] = 0
135
135
  this._benchmarkData[name] = 0
@@ -162,6 +162,7 @@ export class OINOMemoryBenchmark extends OINOBenchmark {
162
162
  this._benchmarkData[category_name] += duration
163
163
  }
164
164
  result = this._benchmarkData[name] / this._benchmarkCount[name]
165
+ this._benchmarkStart[name] = 0
165
166
  }
166
167
  return result
167
168
  }