@@ -125,62 +125,70 @@ filesize.js is optimized for high performance with comprehensive benchmarks cove
125
125
126
126
| Scenario | Operations/sec | Notes |
127
127
| ----------| ----------------| -------|
128
- | ** Basic conversion** | ~ 10-12M ops/sec | Fastest operations (small numbers) |
129
- | ** Large numbers** | ~ 10-11M ops/sec | Consistent performance |
130
- | ** With options** | ~ 4-9M ops/sec | Depends on option complexity |
131
- | ** Locale formatting** | ~ 85K ops/sec | Most expensive operation |
132
- | ** Partial functions ** | ~ 6-8M ops/sec | ~ 10-20% overhead, amortized |
128
+ | ** Basic conversion** | ~ 16-27M ops/sec | Fastest operations (large numbers) |
129
+ | ** Small numbers** | ~ 18-20M ops/sec | Consistent performance |
130
+ | ** With options** | ~ 5-13M ops/sec | Depends on option complexity |
131
+ | ** Locale formatting** | ~ 91K ops/sec | Most expensive operation |
132
+ | ** Stress testing ** | ~ 2-10M ops/sec | Handles edge cases gracefully |
133
133
134
134
### 📊 Detailed Benchmark Results
135
135
136
- #### Basic Performance (5-run average, excluding outliers )
137
- - ** filesize(0)** : 10.1M ops/sec
138
- - ** filesize(512)** : 12 .3M ops/sec
139
- - ** filesize(1024)** : 10.2M ops/sec
140
- - ** filesize(1MB)** : 11.3M ops/sec
141
- - ** filesize(1GB)** : 11.1M ops/sec
142
- - ** With bits=true ** : 9.3M ops/sec
143
- - ** With standard="iec" ** : 9.6M ops/sec
144
- - ** With fullform=true ** : 4.4M ops/sec
145
- - ** Object output ** : 5.1M ops/sec
136
+ #### Basic Performance (5-run average)
137
+ - ** filesize(0)** : 18.6M ops/sec
138
+ - ** filesize(512)** : 20 .3M ops/sec
139
+ - ** filesize(1024)** : 18.7M ops/sec
140
+ - ** filesize(1MB)** : 23.5M ops/sec
141
+ - ** filesize(1GB)** : 23.6M ops/sec
142
+ - ** filesize(1TB) ** : 26.9M ops/sec
143
+ - ** With bits=true ** : 16.8M ops/sec
144
+ - ** With standard="iec" ** : 16.6M ops/sec
145
+ - ** With round=4 ** : 13.4M ops/sec
146
146
147
147
#### Options Performance Impact
148
- - ** Default options** : 6.4M ops/sec (baseline)
149
- - ** bits=true** : 1.66x slower
150
- - ** pad=true** : 2.74x slower
151
- - ** locale="en-US"** : 75x slower (significant overhead)
152
- - ** standard="iec"** : 1.12x slower
153
- - ** output="object"** : 0.96x faster
154
- - ** Complex combinations** : 1.6-2.1x slower
148
+ - ** bits=true** : 12.5M ops/sec
149
+ - ** pad=true** : 5.6M ops/sec
150
+ - ** locale="en-US"** : 91K ops/sec (significant overhead)
151
+ - ** standard="iec"** : 8.8M ops/sec
152
+ - ** standard="jedec"** : 9.0M ops/sec
153
+ - ** output="array"** : 10.2M ops/sec
154
+ - ** output="object"** : 9.2M ops/sec
155
+ - ** fullform=true** : 7.8M ops/sec
156
+ - ** precision=3** : 6.3M ops/sec
157
+ - ** separator=","** : 7.2M ops/sec
155
158
156
159
#### Stress Test Results
157
- - ** Edge cases** : 2.0M ops/sec (90% success rate)
158
- - ** Very large numbers** : 3.7M ops/sec (100% success)
159
- - ** BigInt values** : 2.8M ops/sec (100% success)
160
- - ** Memory pressure** : 48K ops/sec (100% success)
161
- - ** Performance consistency** : 84.7% (10 runs average)
160
+ - ** Edge cases** : 2.3M ops/sec (90% success rate)
161
+ - ** Very large numbers** : 4.6M ops/sec (100% success)
162
+ - ** Very small numbers** : 10.4M ops/sec (100% success)
163
+ - ** Negative numbers** : 5.4M ops/sec (100% success)
164
+ - ** Random options** : 2.3M ops/sec (100% success)
165
+ - ** BigInt values** : 3.7M ops/sec (100% success)
166
+ - ** Memory pressure** : 49K ops/sec (100% success)
167
+ - ** Error conditions** : 715K ops/sec (~ 40% success rate)
162
168
163
169
#### Partial Function Performance
164
- - ** Direct calls ** : 8.0M ops/sec (baseline)
165
- - ** Simple partial ** : 6.7M ops/sec (1.20x slower)
166
- - ** Complex partial ** : 5.6M ops/sec (1.42x slower)
167
- - ** Partial with locale ** : 84K ops/sec (95x slower)
170
+ Partial functions maintain excellent performance with minimal overhead:
171
+ - ** Acceptable overhead ** : 1.1-1.4x slower for most configurations
172
+ - ** Locale partials ** : Significant overhead ( ~ 180x slower) due to locale formatting
173
+ - ** Creation cost ** : Amortized across multiple uses
168
174
169
175
### 💡 Performance Insights
170
176
171
- ** Excellent Performance (>1M ops/sec)**
177
+ ** Excellent Performance (>10M ops/sec)**
172
178
- Basic conversions with minimal options
179
+ - Large number processing (1TB+ values)
173
180
- Standard output formats (string, array, object)
174
181
- IEC and JEDEC standards
175
182
176
- ** Good Performance (100K-1M ops/sec)**
183
+ ** Good Performance (1-10M ops/sec)**
177
184
- Complex option combinations
178
185
- Precision and rounding operations
179
186
- Fullform output
187
+ - Stress test scenarios
180
188
181
189
** Use Sparingly (<100K ops/sec)**
182
- - Locale formatting (significant overhead)
183
- - Complex locale configurations
190
+ - Locale formatting (significant overhead ~ 91K ops/sec )
191
+ - Memory pressure conditions
184
192
185
193
### 🎯 Optimization Tips
186
194
@@ -215,7 +223,7 @@ The latest version includes significant performance improvements:
215
223
216
224
** Overall performance improvement: 30-70% faster** across common use cases while maintaining full backward compatibility.
217
225
218
- * Benchmarks run on macOS ARM64, Node.js v23.10 .0, 12 CPU cores, 24GB RAM*
226
+ * Benchmarks run on macOS ARM64, Node.js v24.8 .0, 12 CPU cores, 24GB RAM (5-run averages) *
219
227
220
228
## API Reference
221
229
@@ -447,23 +455,61 @@ filesize.js/
447
455
6 . Push to the branch (` git push origin feature/amazing-feature ` )
448
456
7 . Open a Pull Request
449
457
458
+ ### Development Workflow
459
+
460
+ filesize.js includes an optimized development workflow with modern build tools:
461
+
462
+ * ** 🔄 Live Reload** : Use ` npm run dev ` for automatic rebuilds during development
463
+ * ** 📊 Bundle Analysis** : Monitor build sizes with ` npm run build:analyze `
464
+ * ** ⚡ Fast Testing** : Live test running with ` npm run test:watch `
465
+ * ** 🔧 Auto-fixing** : Automatic linting fixes with ` npm run lint:fix `
466
+ * ** 📈 Performance** : Optimized Rollup configuration with enhanced tree shaking
467
+
468
+ ** Build Output Analysis:**
469
+ - Minified ES Module: ~ 1.8KB (gzipped)
470
+ - UMD Bundle: ~ 1.9KB (gzipped)
471
+ - Comprehensive source maps included
472
+
450
473
### Development Commands
451
474
452
475
``` bash
453
476
# Install dependencies
454
477
npm install
455
478
479
+ # Development mode with live rebuild
480
+ npm run dev
481
+
482
+ # Build distribution
483
+ npm run build
484
+
485
+ # Build with bundle size analysis
486
+ npm run build:analyze
487
+
488
+ # Live rebuild during development
489
+ npm run build:watch
490
+
456
491
# Run linting
457
492
npm run lint
458
493
494
+ # Auto-fix linting issues
495
+ npm run lint:fix
496
+
459
497
# Run tests
460
498
npm test
461
499
462
- # Build distribution
463
- npm run build
500
+ # Live testing during development
501
+ npm run test:watch
502
+
503
+ # Run only unit tests
504
+ npm run mocha
505
+
506
+ # Bundle size analysis
507
+ npm run analyze:size
464
508
465
- # Run all checks (lint + test)
466
- npm run ci
509
+ # Benchmarking
510
+ npm run benchmark
511
+ npm run benchmark:basic
512
+ npm run benchmark:stress
467
513
```
468
514
469
515
## License
0 commit comments