big.esm 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/README.md +47 -39
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [1.1.2](https://github.com/dschewchenko/big.esm/compare/v1.1.1...v1.1.2) (2023-05-14)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* benchmark update and readme notes ([7b8d446](https://github.com/dschewchenko/big.esm/commit/7b8d446be55eb0f0979ab310491e9bb685215753))
|
|
7
|
+
|
|
1
8
|
## [1.1.1](https://github.com/dschewchenko/big.esm/compare/v1.1.0...v1.1.1) (2023-05-14)
|
|
2
9
|
|
|
3
10
|
|
package/README.md
CHANGED
|
@@ -7,22 +7,20 @@ Library for working with large numbers and fractions using `BigInt`.
|
|
|
7
7
|
It provides advanced functionality for performing arithmetic operations with precision and decimal handling.
|
|
8
8
|
[Documentation](https://dschewchenko.github.io/big.esm/).
|
|
9
9
|
|
|
10
|
-
100% test coverage.
|
|
10
|
+
- 100% test coverage.
|
|
11
11
|
|
|
12
|
-
No dependencies.
|
|
12
|
+
- No dependencies.
|
|
13
13
|
|
|
14
|
-
No limitations on the size of the numbers, except for the limitations of `BigInt`, so limited by system memory =).
|
|
14
|
+
- No limitations on the size of the numbers, except for the limitations of `BigInt`, so limited by system memory =).
|
|
15
15
|
|
|
16
|
-
Fully written in TypeScript, so it provides type definitions out of the box.
|
|
16
|
+
- Fully written in TypeScript, so it provides type definitions out of the box.
|
|
17
17
|
|
|
18
|
-
Tree-shaking is supported.
|
|
18
|
+
- Tree-shaking is supported.
|
|
19
19
|
|
|
20
20
|
Full bundle size(ESM) — 3.12 kB minified and 1.42 kB gzipped.
|
|
21
21
|
`powBig` operation is half of this size, 1.5kB/0.7kB(minified/gzip),
|
|
22
22
|
because it's big and reuses most of the operations from `big.esm`.
|
|
23
23
|
|
|
24
|
-
Full bundle size(UMD) — 3.43 kB minified and 1.57 kB gzipped.
|
|
25
|
-
|
|
26
24
|
## Installation
|
|
27
25
|
|
|
28
26
|
Install `big.esm` using npm:
|
|
@@ -121,44 +119,54 @@ Compares two `Big` instances. Returns `-1` if `a < b`, `0` if `a == b` and `1` i
|
|
|
121
119
|
|
|
122
120
|
Compare `big.esm` with `big.js`. 100_000 iterations for each operation.
|
|
123
121
|
|
|
124
|
-
| Operation
|
|
125
|
-
|
|
126
|
-
| init - smallInt
|
|
127
|
-
| add - smallInt
|
|
128
|
-
| subtract - smallInt
|
|
129
|
-
| multiply - smallInt
|
|
130
|
-
| divide - smallInt
|
|
131
|
-
| power of 4 - smallInt
|
|
132
|
-
|
|
|
133
|
-
|
|
|
134
|
-
|
|
|
135
|
-
|
|
|
136
|
-
|
|
|
137
|
-
|
|
|
138
|
-
|
|
|
139
|
-
|
|
|
140
|
-
|
|
|
141
|
-
|
|
|
142
|
-
|
|
|
143
|
-
|
|
|
144
|
-
|
|
|
145
|
-
|
|
|
146
|
-
|
|
|
147
|
-
|
|
|
148
|
-
|
|
|
149
|
-
|
|
|
122
|
+
| Operation | big.esm | big.js | Difference |
|
|
123
|
+
|---------------------------|-------------|------------|-----------------|
|
|
124
|
+
| init - smallInt | 40.267ms | 24.225ms | -66.22% slower |
|
|
125
|
+
| add - smallInt | 24.570ms | 16.543ms | -48.52% slower |
|
|
126
|
+
| subtract - smallInt | 22.152ms | 16.455ms | -34.63% slower |
|
|
127
|
+
| multiply - smallInt | 23.394ms | 25.183ms | 7.10% faster |
|
|
128
|
+
| divide - smallInt | 68.486ms | 232.593ms | 70.56% faster |
|
|
129
|
+
| power of 4 - smallInt | 124.721ms | 63.314ms | -96.99% slower |
|
|
130
|
+
| square root - smallInt | 5608.635ms | 1489.536ms | -276.54% slower |
|
|
131
|
+
| init - smallNumber | 43.917ms | 38.125ms | -15.19% slower |
|
|
132
|
+
| add - smallNumber | 22.342ms | 26.888ms | 16.91% faster |
|
|
133
|
+
| subtract - smallNumber | 21.692ms | 27.138ms | 20.07% faster |
|
|
134
|
+
| multiply - smallNumber | 27.452ms | 56.488ms | 51.40% faster |
|
|
135
|
+
| divide - smallNumber | 62.497ms | 318.407ms | 80.37% faster |
|
|
136
|
+
| power of 4 - smallNumber | 153.008ms | 156.773ms | 2.40% faster |
|
|
137
|
+
| square root - smallNumber | 5557.749ms | 1558.616ms | -256.58% slower |
|
|
138
|
+
| init - bigInt | 50.074ms | 36.019ms | -39.02% slower |
|
|
139
|
+
| add - bigInt | 27.391ms | 24.467ms | -11.95% slower |
|
|
140
|
+
| subtract - bigInt | 27.009ms | 24.022ms | -12.43% slower |
|
|
141
|
+
| multiply - bigInt | 33.851ms | 120.812ms | 71.98% faster |
|
|
142
|
+
| divide - bigInt | 77.744ms | 714.170ms | 89.11% faster |
|
|
143
|
+
| power of 4 - bigInt | 248.630ms | 498.119ms | 50.09% faster |
|
|
144
|
+
| square root - bigInt | 16917.234ms | 5955.270ms | -184.07% slower |
|
|
145
|
+
| init - bigNumber | 60.159ms | 85.812ms | 29.89% faster |
|
|
146
|
+
| add - bigNumber | 33.340ms | 56.803ms | 41.31% faster |
|
|
147
|
+
| subtract - bigNumber | 34.255ms | 54.496ms | 37.14% faster |
|
|
148
|
+
| multiply - bigNumber | 50.376ms | 452.010ms | 88.86% faster |
|
|
149
|
+
| divide - bigNumber | 80.627ms | 1376.583ms | 94.14% faster |
|
|
150
|
+
| power of 4 - bigNumber | 553.183ms | 2005.740ms | 72.42% faster |
|
|
151
|
+
| square root - bigNumber | 17023.515ms | 5104.271ms | -233.52% slower |
|
|
152
|
+
|
|
153
|
+
Note 1: Square root is slower because it uses Newton's method with variable root(quadratic, cubic, etc.ій) and high precision.
|
|
154
|
+
The more precise the result, the more iterations are required.
|
|
155
|
+
|
|
156
|
+
Node 2: On small numbers big.esm is slower because it uses bigint, which is slower on initialization.
|
|
157
|
+
And each operation returns a new instance of Big, without mutating the original instance.
|
|
150
158
|
|
|
151
159
|
#### Test data:
|
|
152
160
|
|
|
153
161
|
```js
|
|
154
|
-
const smallIntA =
|
|
155
|
-
const smallIntB =
|
|
156
|
-
const smallNumberA =
|
|
157
|
-
const smallNumberB =
|
|
162
|
+
const smallIntA = 12345;
|
|
163
|
+
const smallIntB = 45678;
|
|
164
|
+
const smallNumberA = 12345.67809;
|
|
165
|
+
const smallNumberB = 78901.23456;
|
|
158
166
|
const bigIntA = "12345678901234567890";
|
|
159
167
|
const bigIntB = "67890123456789012345";
|
|
160
|
-
const bigNumberA = "12345678901234567890.
|
|
161
|
-
const bigNumberB = "67890123456789012345.
|
|
168
|
+
const bigNumberA = "12345678901234567890.12345678901234567890"
|
|
169
|
+
const bigNumberB = "67890123456789012345.67890123456789012345";
|
|
162
170
|
```
|
|
163
171
|
|
|
164
172
|
Benchmarked on MacBook Pro M1 2021.
|