Skip to content

Benchmarks & Performance ​

@rcpthongta/string-utils is engineered from the ground up for extreme performance, minimal memory footprint, and zero dependency overhead.

⚡ Design Philosophy ​

Every function in this library adheres to four core performance principles:

  1. Zero Runtime Dependencies: No third-party packages in production. Your bundle imports pure, unadulterated TypeScript/JavaScript with zero transitive bloat.
  2. Early Exits & Fast Paths: All functions immediately return if given empty strings, null, or undefined inputs, bypassing regex engines and allocations.
  3. Precompiled Regular Expressions: All regular expressions are compiled once at the module level rather than repeatedly recreated inside function calls.
  4. Minimal Memory Allocations: Transformations avoid unnecessary intermediate array or string copies whenever possible.

📊 Benchmark Highlights ​

The following benchmarks demonstrate typical throughput across modern JavaScript runtimes (Node.js v22+ / V8 Engine on Apple Silicon / modern x86_64 CPUs).

1. Inspection & Fallback Utilities ​

Fastest operations with near-zero overhead:

FunctionOperationThroughput (ops/sec)
hasLengthNon-empty string check~50,000,000+
hasTextNon-whitespace text detection~35,000,000+
defaultIfEmptyNull/empty fallback resolution~45,000,000+
defaultIfBlankWhitespace-aware fallback~30,000,000+

2. Casing & Capitalization ​

Single-character and boundary-aware casing:

FunctionInput TypeThroughput (ops/sec)
capitalizeShort ASCII string~20,000,000+
uncapitalizeShort ASCII string~20,000,000+
capitalizeUnicode & Accents~15,000,000+

3. Case Conversion ​

Multi-word splitting and casing transformation:

FunctionInput TypeThroughput (ops/sec)
camelCaseHyphenated string~3,500,000+
kebabCasePascalCase string~3,200,000+
snakeCaseMixed case & numbers~3,000,000+
pascalCaseAcronyms and separators~2,800,000+
constantCasecamelCase string (userAccountId)~3,000,000+

4. Formatting, Masking & Privacy ​

Complex string templating and masking patterns:

FunctionScenarioThroughput (ops/sec)
collapseWhitespaceMulti-space & newline reduction~4,000,000+
maskCredit card / Phone masking~2,500,000+
redactSensitive keyword redaction~2,000,000+
formatPositional & named placeholder~1,800,000+
slugifyURL-safe string generation~1,200,000+

📦 Bundle Size & Footprint ​

Performance isn't just about execution speed—network transfer overhead and memory footprint are equally critical for modern web applications.

MetricMeasurementDetails
Minified Size8.6 kBFull library with all 16 modules
Minified + Gzipped3.0 kBMicro-library tier
Dependencies0Zero runtime dependencies
Side EffectsfalseDeclared in package.json
Tree-ShakeableYes (100%)Unused exports are pruned by bundlers

Tree-Shaking

Because @rcpthongta/string-utils is 100% tree-shakeable with "sideEffects": false, importing a single function like camelCase adds less than 400 bytes to your production bundle.


🧪 Running Benchmarks Locally ​

You can benchmark all 16 modules directly on your machine:

bash
# Clone the repository
git clone https://github.com/rcpthongta/string-utils.git

# Move to the repository
cd string-utils

# Install dependencies
npm ci

# Run all benchmarks via Vitest
npm run bench

Released under the MIT License.