Comparing version 2.0.0-dev.20240517 to 2.0.0-dev.20240520
@@ -42,3 +42,3 @@ try{ | ||
'1.5.0-dev.2024042406', '2.0.0-dev.20240511', '2.0.0-dev.20240513', | ||
'2.0.0-dev.20240514', '2.0.0-dev.20240517' | ||
'2.0.0-dev.20240514', '2.0.0-dev.20240517', '2.0.0-dev.20240520' | ||
]; a_calc_versions; | ||
@@ -45,0 +45,0 @@ } |
{ | ||
"name": "a-calc", | ||
"version": "2.0.0-dev.20240517", | ||
"version": "2.0.0-dev.20240520", | ||
"description": "A very powerful and easy-to-use number precision calculation and formatting library.", | ||
@@ -5,0 +5,0 @@ "main": "./es/index.js", |
@@ -283,2 +283,25 @@ # a-calc | ||
### Enable calculation caching. | ||
The `calc`, `fmt`, and `calc_wrap` methods all have corresponding caching methods. The method names are simply the original names followed by `_memo`. The usage is the same as the non-cached versions, but with the added built-in caching functionality. | ||
```typescript | ||
import { calc_memo, fmt_memo, calc_wrap } from "a-calc" | ||
``` | ||
These caching methods are not suitable for computing completely random expressions, but even for completely random expressions, there is a way to transform them into versions that can take advantage of caching. The prerequisite is that the formulas between different expressions can be reused. Here is an example: | ||
```typescript | ||
// The following calculation formula cannot be reused and is not suitable for cached computation. | ||
calc(`${Math.Random()} + ${Math.Random()}`) | ||
calc(`${Math.Random()} + ${Math.Random()}`) | ||
// The following calculation formula is suitable for using cached computation. | ||
calc_memo("a + b", {a: Math.Random(), b: Math.Random()}) | ||
calc_memo("a + b", {a: Math.Random(), b: Math.Random()}) | ||
``` | ||
It can be seen that once we extract a formula like `a + b` from the calculation above, it can be reused. However, please note that `a + b` and `c + d` are considered different formulas! | ||
In conclusion, effectively utilizing caching in calculations can significantly improve performance. This is one of the most impactful techniques for enhancing performance among all performance improvement strategies. | ||
### The space and space-all modes | ||
@@ -285,0 +308,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
427
234824
923