Skip to content

Commit c9cbde9

Browse files
committed
Adding creation time to perf test
1 parent 67fde9b commit c9cbde9

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

tests/ClassTest.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const mem1 = process.memoryUsage();
2+
const time1 = process.hrtime.bigint();
23

34
class Counter {
45
valueInternal;
@@ -19,11 +20,33 @@ class Counter {
1920
onSubtract() {
2021
this.valueInternal--;
2122
}
23+
24+
someOtherFunction1() {
25+
console.log(this.valueInternal);
26+
}
27+
someOtherFunction2() {
28+
console.log(this.valueInternal);
29+
}
30+
someOtherFunction3() {
31+
console.log(this.valueInternal);
32+
}
33+
someOtherFunction4() {
34+
console.log(this.valueInternal);
35+
}
36+
someOtherFunction5() {
37+
console.log(this.valueInternal);
38+
}
39+
someOtherFunction6() {
40+
console.log(this.valueInternal);
41+
}
2242
}
2343

2444
const getInstance2 = props => new Counter(props);
2545

2646
const instances = new Array(1000).fill({}).map(getInstance2);
47+
48+
const time2 = process.hrtime.bigint();
2749
const mem2 = process.memoryUsage();
2850

29-
console.log(`Memory Used: ${mem2.heapUsed - mem1.heapUsed} bytes`); // Memory Used: 127248 bytes
51+
console.log(`Memory Used: ${mem2.heapUsed - mem1.heapUsed} bytes`); // Memory Used: 128528 bytes
52+
console.log(`Time taken: ${time2 - time1} nanoseconds`); // Time taken: 586271 nanoseconds

tests/ClosureTest.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const mem1 = process.memoryUsage();
2+
const time1 = process.hrtime.bigint();
23

34
const getInstance = props => {
45
const valueInternal = props.value;
@@ -11,11 +12,33 @@ const getInstance = props => {
1112
},
1213
onSubtract() {
1314
valueInternal.value--;
15+
},
16+
17+
someOtherFunction1() {
18+
console.log(valueInternal.value);
19+
},
20+
someOtherFunction2() {
21+
console.log(valueInternal.value);
22+
},
23+
someOtherFunction3() {
24+
console.log(valueInternal.value);
25+
},
26+
someOtherFunction4() {
27+
console.log(valueInternal.value);
28+
},
29+
someOtherFunction5() {
30+
console.log(valueInternal.value);
31+
},
32+
someOtherFunction6() {
33+
console.log(valueInternal.value);
1434
}
1535
};
1636
};
1737

1838
const instances = new Array(1000).fill({}).map(getInstance);
39+
40+
const time2 = process.hrtime.bigint();
1941
const mem2 = process.memoryUsage();
2042

21-
console.log(`Memory Used: ${mem2.heapUsed - mem1.heapUsed} bytes`); //Memory Used: 239656 bytes
43+
console.log(`Memory Used: ${mem2.heapUsed - mem1.heapUsed} bytes`); // Memory Used: 532792 bytes
44+
console.log(`Time taken: ${time2 - time1} nanoseconds`); // Time taken: 1573748 nanoseconds

0 commit comments

Comments
 (0)