@@ -69,59 +69,6 @@ test("reduce method", () => {
6969 expect ( total ) . toEqual ( 15 ) ;
7070} ) ;
7171
72- /**
73- * Stress testing the iter implementation and making sure it performs better than default .map .filter methods.
74- */
75- test ( "Performance comparison with native array methods" , ( ) => {
76- // Create a large array
77- const size = 1_000_000 ;
78- const largeArray = Array . from ( { length : size } , ( _ , i ) => i ) ;
79-
80- // Test native array methods
81- console . time ( "Native array methods" ) ;
82- const nativeStartTime = performance . now ( ) ;
83- const nativeResult = largeArray
84- . map ( ( x ) => x * 2 )
85- . map ( ( x ) => x * 2 )
86- . map ( ( x ) => x * 2 )
87- . filter ( ( x ) => x % 3 === 0 )
88- . map ( ( x ) => x + 1 ) ;
89- const nativeEndTime = performance . now ( ) ;
90- const nativeDuration = nativeEndTime - nativeStartTime ;
91- console . timeEnd ( "Native array methods" ) ;
92-
93- // Test iter implementation
94- console . time ( "iter implementation" ) ;
95-
96- const iterResultInit = iter ( largeArray )
97- . map ( ( x ) => x * 2 )
98- . map ( ( x ) => x * 2 )
99- . map ( ( x ) => x * 2 )
100- . filter ( ( x ) => x % 3 === 0 )
101- . map ( ( x ) => x + 1 ) ;
102-
103- const iterStartTime = performance . now ( ) ;
104- const iterResult = iterResultInit . collect ( ) ;
105- const iterEndTime = performance . now ( ) ;
106- const iterDuration = iterEndTime - iterStartTime ;
107- console . timeEnd ( "iter implementation" ) ;
108-
109- // Verify both implementations produce the same result
110- expect ( iterResult ) . toEqual ( nativeResult ) ;
111-
112- // Verify iter implementation is faster
113- expect ( iterDuration ) . toBeLessThan ( nativeDuration ) ;
114- // Log performance comparison
115- console . log ( `Native duration: ${ nativeDuration . toFixed ( 2 ) } ms` ) ;
116- console . log ( `Iter duration: ${ iterDuration . toFixed ( 2 ) } ms` ) ;
117- console . log (
118- `Improvement: ${ (
119- ( ( nativeDuration - iterDuration ) / nativeDuration ) *
120- 100
121- ) . toFixed ( 2 ) } %`
122- ) ;
123- } ) ;
124-
12572test ( "Performance comparison with objects" , ( ) => {
12673 // Create a large array of user profiles
12774 const size = 100_000 ;
0 commit comments