Skip to content

Commit

Permalink
docs(readme): update
Browse files Browse the repository at this point in the history
  • Loading branch information
unadlib committed Dec 21, 2024
1 parent 6384324 commit 05123d5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 40 deletions.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,18 @@ Measure(ops/sec) to update 50K arrays and 1K objects, bigger is better([view sou
![Benchmark](benchmark.jpg)

```
Coaction x 4,837 ops/sec ±3.79% (65 runs sampled)
Coaction with Mutative x 4,276 ops/sec ±3.04% (85 runs sampled)
Zustand x 4,753 ops/sec ±3.52% (75 runs sampled)
Zustand with Immer x 251 ops/sec ±0.26% (93 runs sampled)
Zustand with Mutative x 4,292 ops/sec ±3.30% (72 runs sampled)
Coaction x 5,272 ops/sec ±3.08% (63 runs sampled)
Coaction with Mutative x 4,626 ops/sec ±2.26% (83 runs sampled)
Zustand x 5,233 ops/sec ±2.68% (79 runs sampled)
Zustand with Immer x 253 ops/sec ±0.26% (93 runs sampled)
The fastest method is Coaction,Zustand
```

According to the provided performance data, Coaction's performance is comparable to Zustand's performance. However, Coaction with Mutative demonstrates a significant performance advantage compared to Zustand with Immer.

While standard Coaction achieves approximately 5,272 operations per second (ops/sec) and standard Zustand reaches around 5,233 ops/sec, the most striking difference is observed with Zustand with Immer, which drastically drops to a mere 253 ops/sec. Furthermore, Coaction with Mutative achieves around 4,626 ops/sec. This means Coaction with Mutative is approximately 18.3 times faster than Zustand with Immer (4626 / 253 ≈ 18.3). The data clearly indicates that Coaction offers superior performance characteristics compared to Zustand, and this advantage is especially pronounced when contrasted with Zustand's Immer implementation.

> We will also provide more complete benchmarking.
## Installation
Expand Down
Binary file modified benchmark.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/core/src/handleState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const handleState = <T extends CreateState>(
internal.rootState = createWithMutative(
internal.rootState,
(draft) => {
internal.rootState = draft as Draft<any>;
internal.rootState = draft as Draft<T>;
return next(internal.module);
}
);
Expand Down
38 changes: 4 additions & 34 deletions scripts/benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import QuickChart from 'quickchart-js';
import { create as createWithCoaction } from 'coaction';
import { create as createWithZustand } from 'zustand';
import { immer } from 'zustand/middleware/immer';
import { mutative } from 'zustand-mutative';

const labels: string[] = [];
const result = [
Expand All @@ -20,18 +19,13 @@ const result = [
data: []
},
{
label: 'Zustand with Immer',
backgroundColor: 'rgba(255, 0, 0, 0.5)',
data: []
},
{
label: 'Zustand with Mutative',
label: 'Coaction with Mutative',
backgroundColor: 'rgba(255, 0, 217, 0.5)',
data: []
},
{
label: 'Coaction with Mutative',
backgroundColor: 'rgba(255, 120, 120, 0.5)',
label: 'Zustand with Immer',
backgroundColor: 'rgba(255, 0, 0, 0.5)',
data: []
}
];
Expand Down Expand Up @@ -165,30 +159,6 @@ suite
}
}
)
.add(
'Zustand with Mutative',
() => {
store.getState().update();
},
{
onStart: () => {
i = Math.random();
baseState = getData();
store = createWithZustand(
mutative<Store>((set) => ({
arr: baseState.arr,
map: baseState.map,
update: () => {
set((state) => {
state.arr.push(i);
state.map[i] = { i };
});
}
}))
);
}
}
)
.on('cycle', (event: any) => {
console.log(String(event.target));
const [name, field = 'Update'] = event.target.name.split(' - ');
Expand All @@ -212,7 +182,7 @@ try {
options: {
title: {
display: true,
text: 'Coaction vs Zustand vs Zustand with Immer Performance'
text: 'Coaction vs Zustand Performance'
},
legend: {
position: 'bottom'
Expand Down

0 comments on commit 05123d5

Please sign in to comment.