MCPcopy
hub / github.com/formatjs/formatjs / run

Function run

packages/intl-numberformat/benchmark/benchmark.ts:37–99  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

35})
36
37async function run() {
38 const bench = new Bench({time: 1000})
39
40 bench
41 // Basic decimal formatting (most common case)
42 .add('format decimal (polyfill)', () => {
43 testValues.forEach(val => nf.format(val))
44 })
45 .add('format decimal (native)', () => {
46 testValues.forEach(val => nativeNf.format(val))
47 })
48
49 // Percent formatting
50 .add('format percent (polyfill)', () => {
51 testValues.forEach(val => nfPercent.format(val))
52 })
53 .add('format percent (native)', () => {
54 testValues.forEach(val => nativeNfPercent.format(val))
55 })
56
57 // Currency formatting
58 .add('format currency (polyfill)', () => {
59 testValues.forEach(val => nfCurrency.format(val))
60 })
61 .add('format currency (native)', () => {
62 testValues.forEach(val => nativeNfCurrency.format(val))
63 })
64
65 // Unit formatting
66 .add('format unit (polyfill)', () => {
67 testValues.forEach(val => nfUnit.format(val))
68 })
69
70 // Significant digits (uses ToRawPrecision - performance hotspot)
71 .add('format with significantDigits (polyfill)', () => {
72 testValues.forEach(val => nfSignificantDigits.format(val))
73 })
74
75 // Fraction digits (uses ToRawFixed)
76 .add('format with fractionDigits (polyfill)', () => {
77 testValues.forEach(val => nfFractionDigits.format(val))
78 })
79
80 // Real-world scenario: formatting time values (0-59) - matches issue description
81 .add('format time values 0-59 (polyfill)', () => {
82 dateValues.forEach(val => nf.format(val))
83 })
84 .add('format time values 0-59 (native)', () => {
85 dateValues.forEach(val => nativeNf.format(val))
86 })
87
88 // formatToParts (heavier operation)
89 .add('formatToParts decimal (polyfill)', () => {
90 testValues.forEach(val => nf.formatToParts(val))
91 })
92 .add('formatToParts decimal (native)', () => {
93 testValues.forEach(val => nativeNf.formatToParts(val))
94 })

Callers 1

benchmark.tsFile · 0.70

Calls 3

formatMethod · 0.65
formatToPartsMethod · 0.65
runMethod · 0.65

Tested by

no test coverage detected