Skip to content

Commit f8b479d

Browse files
committed
feat(computed): add benchmark for updating a computed with many dependencies
1 parent 0f188ce commit f8b479d

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/computed.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,23 @@ function go() {
101101
});
102102
});
103103

104+
bench(() => {
105+
const refs = [];
106+
for (let i = 0, n = 1000; i < n; i++) {
107+
refs.push(ref(i));
108+
}
109+
const c = computed(() => {
110+
let total = 0;
111+
refs.forEach(ref => total += ref.value);
112+
return total;
113+
});
114+
let i = 0;
115+
const n = refs.length;
116+
return suite.add("1000 refs, 1 computed", () => {
117+
refs[i++ % n].value++;
118+
const v = c.value;
119+
});
120+
});
121+
104122
return suite;
105123
}

0 commit comments

Comments
 (0)