packages/intl-numberformat/benchmark/PROFILE.md
This guide explains how to profile and analyze the performance of @formatjs/intl-numberformat using Node.js's built-in CPU profiler.
bazel run //packages/intl-numberformat/benchmark:profile_cpu
bazel run //packages/intl-numberformat/benchmark:analyze_profile
bazel run //packages/intl-numberformat/benchmark:profile_cpu
What this does:
--cpu-prof flag enabled.cpuprofile file in /tmp/Output:
Starting profiling...
Warming up...
Running profiled iterations...
Total time: 3.376s
Completed 900000 format() calls
Profile file location: /tmp/CPU.*.cpuprofile
bazel run //packages/intl-numberformat/benchmark:analyze_profile
The analyzer will automatically find and analyze the most recent .cpuprofile file in /tmp/.
# Using positional argument
bazel run //packages/intl-numberformat/benchmark:analyze_profile -- /tmp/CPU.20251222.230039.35420.0.001.cpuprofile
# Using --profile flag
bazel run //packages/intl-numberformat/benchmark:analyze_profile -- --profile /tmp/CPU.20251222.230039.35420.0.001.cpuprofile
# Using -p shorthand
bazel run //packages/intl-numberformat/benchmark:analyze_profile -- -p /tmp/CPU.20251222.230039.35420.0.001.cpuprofile
The analyzer provides two comprehensive views:
Shows individual functions sorted by CPU time:
Top 40 functions by CPU time (hit count):
==========================================
1. Decimal [decimal.js:4291]
Hit count: 6317
File: file:///Users/.../node_modules/decimal.js/decimal.js
2. P.times.P.mul [decimal.js:1871]
Hit count: 4872
File: file:///Users/.../node_modules/decimal.js/decimal.js
...
What each field means:
(anonymous) for unnamed functions)[filename:line]Aggregated view showing which files consume the most CPU time:
Top 20 files by CPU time:
=========================
1. decimal.js/decimal.js: 21575 hits
2. ecma402-abstract/NumberFormat/format_to_parts.ts: 3080 hits
3. ecma402-abstract/NumberFormat/ToRawFixed.ts: 947 hits
...
Filters:
node:internal).cpuprofile file from /tmp/Benefits:
.cpuprofile file in VS CodeBenefits:
node packages/intl-numberformat/benchmark/analyze-profile.ts /tmp/CPU.*.cpuprofile
| Target | Description |
|---|---|
profile | Quick timing test without profiling |
profile_cpu | CPU profiling with .cpuprofile output |
analyze_profile | Analyze .cpuprofile files |
benchmark | Full benchmark suite |
Look for:
After our optimizations:
Math.log10()Decimal.pow() calls# Check if files exist
ls -lth /tmp/CPU.*.cpuprofile | head -5
# If empty, try running the profiler again
bazel run //packages/intl-numberformat/benchmark:profile_cpu
The profiler writes to /tmp/ by default. To change this:
BUILD.bazel and modify --cpu-prof-dir=/tmpanalyze-profile.ts line 106# Clean build cache
bazel clean
# Rebuild
bazel build //packages/intl-numberformat/benchmark:all
If you can't write to /tmp/:
# Use a different directory
mkdir -p ~/profiles
# Then update BUILD.bazel: --cpu-prof-dir=$HOME/profiles
When adding profiling capabilities:
profile.ts