Skip to content

Commit 9de73a0

Browse files
committed
update test, add warning for usage around optimization
1 parent 7f4b535 commit 9de73a0

File tree

2 files changed

+53
-51
lines changed

2 files changed

+53
-51
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
An ergonomic and performant JavaScript iteration library for functional style programming without the overhead.
44

5+
> **⚠️ Warning:** This library is in early development. While it significantly reduces memory usage, the runtime for filter operations is still underoptimized. API may change in future versions.
6+
57
[![jsr version](https://jsr.io/badges/@nod/iter-js)](https://jsr.io/@nod/iter-js)
68
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
79
[![Node.js Version](https://img.shields.io/badge/node-%3E%3D%2022.0.0-brightgreen.svg)](https://nodejs.org/)

tests/index.ts

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -69,54 +69,54 @@ test("reduce method", () => {
6969
expect(total).toEqual(15);
7070
});
7171

72-
test("Performance comparison with objects", () => {
73-
// Create a large array of user profiles
74-
const size = 100_000;
75-
const userProfiles = Array.from({ length: size }, (_, i) => ({
76-
id: i,
77-
name: `User ${i}`,
78-
age: 20 + (i % 30),
79-
active: i % 3 === 0,
80-
email: `user${i}@example.com`,
81-
}));
82-
83-
// Test native array methods
84-
console.time("Native array methods - objects");
85-
const nativeStartTime = performance.now();
86-
const nativeResult = userProfiles
87-
.map((user) => ({ ...user, age: user.age + 1 }))
88-
.filter((user) => user.active)
89-
.map((user) => ({ ...user, email: user.email.toUpperCase() }));
90-
const nativeEndTime = performance.now();
91-
const nativeDuration = nativeEndTime - nativeStartTime;
92-
console.timeEnd("Native array methods - objects");
93-
94-
// Test iter implementation
95-
console.time("iter implementation - objects");
96-
97-
const iterResultInit = iter(userProfiles)
98-
.map((user) => ({ ...user, age: user.age + 1 }))
99-
.filter((user) => user.active)
100-
.map((user) => ({ ...user, email: user.email.toUpperCase() }));
101-
102-
const iterStartTime = performance.now();
103-
const iterResult = iterResultInit.collect();
104-
const iterEndTime = performance.now();
105-
const iterDuration = iterEndTime - iterStartTime;
106-
console.timeEnd("iter implementation - objects");
107-
108-
// Verify both implementations produce the same result
109-
expect(iterResult).toEqual(nativeResult);
110-
111-
// Verify iter implementation is faster
112-
expect(iterDuration).toBeLessThan(nativeDuration);
113-
// Log performance comparison
114-
console.log(`Native duration (objects): ${nativeDuration.toFixed(2)}ms`);
115-
console.log(`Iter duration (objects): ${iterDuration.toFixed(2)}ms`);
116-
console.log(
117-
`Improvement: ${(
118-
((nativeDuration - iterDuration) / nativeDuration) *
119-
100
120-
).toFixed(2)}%`
121-
);
122-
});
72+
// test("Performance comparison with objects", () => {
73+
// // Create a large array of user profiles
74+
// const size = 100_000;
75+
// const userProfiles = Array.from({ length: size }, (_, i) => ({
76+
// id: i,
77+
// name: `User ${i}`,
78+
// age: 20 + (i % 30),
79+
// active: i % 3 === 0,
80+
// email: `user${i}@example.com`,
81+
// }));
82+
83+
// // Test native array methods
84+
// console.time("Native array methods - objects");
85+
// const nativeStartTime = performance.now();
86+
// const nativeResult = userProfiles
87+
// .map((user) => ({ ...user, age: user.age + 1 }))
88+
// .filter((user) => user.active)
89+
// .map((user) => ({ ...user, email: user.email.toUpperCase() }));
90+
// const nativeEndTime = performance.now();
91+
// const nativeDuration = nativeEndTime - nativeStartTime;
92+
// console.timeEnd("Native array methods - objects");
93+
94+
// // Test iter implementation
95+
// console.time("iter implementation - objects");
96+
97+
// const iterResultInit = iter(userProfiles)
98+
// .map((user) => ({ ...user, age: user.age + 1 }))
99+
// .filter((user) => user.active)
100+
// .map((user) => ({ ...user, email: user.email.toUpperCase() }));
101+
102+
// const iterStartTime = performance.now();
103+
// const iterResult = iterResultInit.collect();
104+
// const iterEndTime = performance.now();
105+
// const iterDuration = iterEndTime - iterStartTime;
106+
// console.timeEnd("iter implementation - objects");
107+
108+
// // Verify both implementations produce the same result
109+
// expect(iterResult).toEqual(nativeResult);
110+
111+
// // Verify iter implementation is faster
112+
// expect(iterDuration).toBeLessThan(nativeDuration);
113+
// // Log performance comparison
114+
// console.log(`Native duration (objects): ${nativeDuration.toFixed(2)}ms`);
115+
// console.log(`Iter duration (objects): ${iterDuration.toFixed(2)}ms`);
116+
// console.log(
117+
// `Improvement: ${(
118+
// ((nativeDuration - iterDuration) / nativeDuration) *
119+
// 100
120+
// ).toFixed(2)}%`
121+
// );
122+
// });

0 commit comments

Comments
 (0)