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

Function run

packages/intl-durationformat/benchmark/benchmark.ts:49–145  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

47 : null
48
49async function run() {
50 const bench = new Bench({time: 1000})
51
52 bench
53 // Short style formatting (most common)
54 .add('format short style (polyfill)', () => {
55 testDurations.forEach(val => dfShort.format(val))
56 })
57
58 if (nativeDfShort) {
59 bench.add('format short style (native)', () => {
60 testDurations.forEach(val => nativeDfShort.format(val))
61 })
62 }
63
64 bench
65 // Long style formatting
66 .add('format long style (polyfill)', () => {
67 testDurations.forEach(val => dfLong.format(val))
68 })
69
70 if (nativeDfLong) {
71 bench.add('format long style (native)', () => {
72 testDurations.forEach(val => nativeDfLong.format(val))
73 })
74 }
75
76 bench
77 // Narrow style formatting
78 .add('format narrow style (polyfill)', () => {
79 testDurations.forEach(val => dfNarrow.format(val))
80 })
81
82 // Digital style formatting (like 1:30:45)
83 .add('format digital style (polyfill)', () => {
84 testDurations.forEach(val => dfDigital.format(val))
85 })
86
87 if (nativeDfDigital) {
88 bench.add('format digital style (native)', () => {
89 testDurations.forEach(val => nativeDfDigital.format(val))
90 })
91 }
92
93 bench
94 // formatToParts (heavier operation)
95 .add('formatToParts short style (polyfill)', () => {
96 testDurations.forEach(val => dfShort.formatToParts(val))
97 })
98
99 if (nativeDfShort) {
100 bench.add('formatToParts short style (native)', () => {
101 testDurations.forEach(val => nativeDfShort.formatToParts(val))
102 })
103 }
104
105 bench
106 // Video/media duration formatting (common real-world use case)

Callers 1

benchmark.tsFile · 0.70

Calls 3

formatMethod · 0.65
formatToPartsMethod · 0.65
runMethod · 0.65

Tested by

no test coverage detected