File tree Expand file tree Collapse file tree 2 files changed +48
-2
lines changed Expand file tree Collapse file tree 2 files changed +48
-2
lines changed Original file line number Diff line number Diff line change 11const mem1 = process . memoryUsage ( ) ;
2+ const time1 = process . hrtime . bigint ( ) ;
23
34class 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
2444const getInstance2 = props => new Counter ( props ) ;
2545
2646const instances = new Array ( 1000 ) . fill ( { } ) . map ( getInstance2 ) ;
47+
48+ const time2 = process . hrtime . bigint ( ) ;
2749const 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
Original file line number Diff line number Diff line change 11const mem1 = process . memoryUsage ( ) ;
2+ const time1 = process . hrtime . bigint ( ) ;
23
34const 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
1838const instances = new Array ( 1000 ) . fill ( { } ) . map ( getInstance ) ;
39+
40+ const time2 = process . hrtime . bigint ( ) ;
1941const 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
You can’t perform that action at this time.
0 commit comments