Skip to content

Commit 66ea79f

Browse files
authored
Use base 10 when calculating memory (#5810)
1 parent cbbadb4 commit 66ea79f

5 files changed

Lines changed: 72 additions & 59 deletions

File tree

src/test/components/TrackBandwidth.test.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ describe('TrackBandwidth', function () {
164164
screen.getByText('Transfer speed for this sample:')
165165
).toBeInTheDocument();
166166
expect(screen.getByText(/speed/).nextSibling).toHaveTextContent(
167-
'4.66GB\u2069 per second'
167+
'5.00GB\u2069 per second'
168168
);
169169

170170
expect(
@@ -176,14 +176,14 @@ describe('TrackBandwidth', function () {
176176
screen.getByText('Data transferred up to this time:')
177177
).toBeInTheDocument();
178178
expect(screen.getByText(/transferred up to/).nextSibling).toHaveTextContent(
179-
/6.86MB\u2069 \(\u2068\d+(\.\d+)?\u2069 g COe\)/
179+
/7.19MB\u2069 \(\u2068\d+(\.\d+)?\u2069 g COe\)/
180180
);
181181

182182
expect(
183183
screen.getByText('Data transferred in the visible range:')
184184
).toBeInTheDocument();
185185
expect(screen.getByText(/visible range/).nextSibling).toHaveTextContent(
186-
/7.97MB\u2069 \(\u2068\d+(\.\d+)?\u2069 g COe\)/
186+
/8.35MB\u2069 \(\u2068\d+(\.\d+)?\u2069 g COe\)/
187187
);
188188
});
189189

@@ -224,13 +224,13 @@ describe('TrackBandwidth', function () {
224224
moveMouseAtCounter(3, 0);
225225
// Note: Fluent adds isolation characters \u2068 and \u2069 around variables.
226226
expect(screen.getByText(/speed/).nextSibling).toHaveTextContent(
227-
'95.4MB\u2069 per second'
227+
'100MB\u2069 per second'
228228
);
229229
expect(screen.getByText(/visible range:/).nextSibling).toHaveTextContent(
230-
/7.97MB\u2069 \(\u2068\d+(\.\d+)?\u2069 g COe\)/
230+
/8.35MB\u2069 \(\u2068\d+(\.\d+)?\u2069 g COe\)/
231231
);
232232
expect(
233233
screen.getByText(/current selection:/).nextSibling
234-
).toHaveTextContent(/4.77MB\u2069 \(\u2068\d+(\.\d+)?\u2069 g COe\)/);
234+
).toHaveTextContent(/5.00MB\u2069 \(\u2068\d+(\.\d+)?\u2069 g COe\)/);
235235
});
236236
});

src/test/components/__snapshots__/TooltipMarker.test.tsx.snap

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ exports[`TooltipMarker renders properly network markers where content type is bl
342342
Requested bytes
343343
:
344344
</div>
345-
45.9KB
345+
47.0KB
346346
<div
347347
class="tooltipLabel"
348348
>
@@ -538,7 +538,7 @@ exports[`TooltipMarker renders properly network markers where content type is mi
538538
Requested bytes
539539
:
540540
</div>
541-
45.9KB
541+
47.0KB
542542
<div
543543
class="tooltipLabel"
544544
>
@@ -744,7 +744,7 @@ exports[`TooltipMarker renders properly network markers with a preconnect part 2
744744
Requested bytes
745745
:
746746
</div>
747-
45.9KB
747+
47.0KB
748748
<div
749749
class="tooltipLabel"
750750
>
@@ -1014,7 +1014,7 @@ exports[`TooltipMarker renders properly network markers with a preconnect part c
10141014
Requested bytes
10151015
:
10161016
</div>
1017-
45.9KB
1017+
47.0KB
10181018
<div
10191019
class="tooltipLabel"
10201020
>
@@ -1210,7 +1210,7 @@ exports[`TooltipMarker renders properly normal network markers 1`] = `
12101210
Requested bytes
12111211
:
12121212
</div>
1213-
45.9KB
1213+
47.0KB
12141214
<div
12151215
class="tooltipLabel"
12161216
>
@@ -3216,14 +3216,14 @@ exports[`TooltipMarker renders tooltips for various markers: GCMajor-16.5 1`] =
32163216
GC heap size (pre - post)
32173217
:
32183218
</div>
3219-
46.1MB - 36.3MB
3219+
48.4MB - 38.1MB
32203220
<div
32213221
class="tooltipLabel"
32223222
>
32233223
Malloc heap size (pre - post)
32243224
:
32253225
</div>
3226-
23.1MB - 12.1MB
3226+
24.2MB - 12.7MB
32273227
<div
32283228
class="tooltipLabel"
32293229
>
@@ -3362,7 +3362,7 @@ exports[`TooltipMarker renders tooltips for various markers: GCMinor-15.5 1`] =
33623362
Bytes tenured
33633363
:
33643364
</div>
3365-
1.30MB / 1.97MB (66%)
3365+
1.37MB / 2.06MB (66%)
33663366
<div
33673367
class="tooltipLabel"
33683368
>
@@ -3376,7 +3376,7 @@ exports[`TooltipMarker renders tooltips for various markers: GCMinor-15.5 1`] =
33763376
Bytes used
33773377
:
33783378
</div>
3379-
1.97MB / 16.0MB (12%)
3379+
2.06MB / 16.8MB (12%)
33803380
<div
33813381
class="tooltipLabel"
33823382
>
@@ -3397,7 +3397,7 @@ exports[`TooltipMarker renders tooltips for various markers: GCMinor-15.5 1`] =
33973397
Tenured allocation rate
33983398
:
33993399
</div>
3400-
181MB/s
3400+
190MB/s
34013401
<div
34023402
class="tooltipLabel"
34033403
>
@@ -3501,7 +3501,7 @@ exports[`TooltipMarker renders tooltips for various markers: GCSlice-17.5 1`] =
35013501
Trigger (amt/trig)
35023502
:
35033503
</div>
3504-
266MB / 245MB
3504+
279MB / 257MB
35053505
<div
35063506
class="tooltipLabel"
35073507
>

src/test/unit/format-numbers.test.ts

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,27 @@ describe('formatGigaBytes', () => {
2828
});
2929

3030
it('returns large values without fractional digits by default', () => {
31-
expect(formatGigaBytes(1234567890123)).toBe('1,150GB');
31+
expect(formatGigaBytes(1234567890123)).toBe('1,235GB');
3232
});
3333

3434
it('returns values with 2 fractional digits by default', () => {
35-
expect(formatGigaBytes(1234567890)).toBe('1.15GB');
35+
expect(formatGigaBytes(1234567890)).toBe('1.23GB');
3636
});
3737

3838
it('can return values with byte precision', () => {
39-
expect(formatGigaBytes(1234567890, 3, 2, 1)).toBe('1GB 153MB 384KB 722B');
39+
expect(formatGigaBytes(1234567890, 3, 2, 1)).toBe('1GB 234MB 567KB 890B');
4040
});
4141

4242
it('can return values with kilobyte precision', () => {
43-
expect(formatGigaBytes(1234567890, 3, 2, 1024)).toBe('1GB 153MB 385KB');
43+
expect(formatGigaBytes(1234567890, 3, 2, 1000)).toBe('1GB 234MB 568KB');
4444
});
4545

4646
it('can return values with megabyte precision', () => {
47-
expect(formatGigaBytes(1234567890, 3, 2, 1024 ** 2)).toBe('1GB 153MB');
47+
expect(formatGigaBytes(1234567890, 3, 2, 1000 ** 2)).toBe('1GB 235MB');
4848
});
4949

5050
it('can return values with gigabyte precision', () => {
51-
expect(formatGigaBytes(1234567890, 3, 2, 1024 ** 3)).toBe('1GB');
51+
expect(formatGigaBytes(1234567890, 3, 2, 1000 ** 3)).toBe('1GB');
5252
});
5353
});
5454

@@ -58,23 +58,23 @@ describe('formatMegaBytes', () => {
5858
});
5959

6060
it('returns large values without fractional digits by default', () => {
61-
expect(formatMegaBytes(1234567890)).toBe('1,177MB');
61+
expect(formatMegaBytes(1234567890)).toBe('1,235MB');
6262
});
6363

6464
it('returns values with 2 fractional digits by default', () => {
65-
expect(formatMegaBytes(1234567)).toBe('1.18MB');
65+
expect(formatMegaBytes(1234567)).toBe('1.23MB');
6666
});
6767

6868
it('can return values with byte precision', () => {
69-
expect(formatMegaBytes(1234567, 3, 2, 1)).toBe('1MB 181KB 647B');
69+
expect(formatMegaBytes(1234567, 3, 2, 1)).toBe('1MB 234KB 567B');
7070
});
7171

7272
it('can return values with kilobyte precision', () => {
73-
expect(formatMegaBytes(1234567, 3, 2, 1024)).toBe('1MB 182KB');
73+
expect(formatMegaBytes(1234567, 3, 2, 1000)).toBe('1MB 235KB');
7474
});
7575

7676
it('can return values with megabyte precision', () => {
77-
expect(formatMegaBytes(1234567, 3, 2, 1024 ** 2)).toBe('1MB');
77+
expect(formatMegaBytes(1234567, 3, 2, 1000 ** 2)).toBe('1MB');
7878
});
7979
});
8080

@@ -84,19 +84,19 @@ describe('formatKiloBytes', () => {
8484
});
8585

8686
it('returns large values without fractional digits by default', () => {
87-
expect(formatKiloBytes(1234567)).toBe('1,206KB');
87+
expect(formatKiloBytes(1234567)).toBe('1,235KB');
8888
});
8989

9090
it('returns values with 2 fractional digits by default', () => {
91-
expect(formatKiloBytes(1234)).toBe('1.21KB');
91+
expect(formatKiloBytes(1234)).toBe('1.23KB');
9292
});
9393

9494
it('can return values with byte precision', () => {
95-
expect(formatKiloBytes(1234, 3, 2, 1)).toBe('1KB 210B');
95+
expect(formatKiloBytes(1234, 3, 2, 1)).toBe('1KB 234B');
9696
});
9797

9898
it('can return values with kilobyte precision', () => {
99-
expect(formatKiloBytes(1234, 3, 2, 1024)).toBe('1KB');
99+
expect(formatKiloBytes(1234, 3, 2, 1000)).toBe('1KB');
100100
});
101101
});
102102

@@ -110,40 +110,53 @@ describe('formatBytes', () => {
110110
});
111111

112112
it('can return values with the kilobyte unit', () => {
113-
expect(formatBytes(12345)).toBe('12.1KB');
113+
expect(formatBytes(12345)).toBe('12.3KB');
114114
});
115115

116116
it('can return values with the megabyte unit', () => {
117-
expect(formatBytes(1234567)).toBe('1.18MB');
117+
expect(formatBytes(1234567)).toBe('1.23MB');
118118
});
119119

120120
it('can return values with the gigabyte unit', () => {
121-
expect(formatBytes(1234567890)).toBe('1.15GB');
121+
expect(formatBytes(1234567890)).toBe('1.23GB');
122122
});
123123

124124
it('can return values with byte precision', () => {
125-
expect(formatBytes(12345, 3, 2, 1)).toBe('12KB 57B');
125+
expect(formatBytes(12345, 3, 2, 1)).toBe('12KB 345B');
126126
});
127127

128128
it('can return values with kilobyte precision', () => {
129-
expect(formatBytes(12345, 3, 2, 1024)).toBe('12KB');
129+
expect(formatBytes(12345, 3, 2, 1000)).toBe('12KB');
130130
});
131131
});
132132

133133
describe('findRoundBytesValueGreaterOrEqualTo', () => {
134-
const expectedValues = [0, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000];
135-
136-
it('rounds small bytes values using base 10 round value', () => {
134+
const expectedValues = [
135+
// minValue, expected
136+
// minValue <= 1000
137+
[0, 0],
138+
[3, 5],
139+
[63, 100],
140+
[511, 1000],
141+
[1000, 2000],
142+
143+
// 1000 < minValue <= 1000^4
144+
[2047, 4000],
145+
[9999, 16000],
146+
[123456, 128000],
147+
[999999, 1000000],
148+
[1_234_567, 2_000_000],
149+
[1_234_567_891, 2_000_000_000],
150+
151+
// minValue > 1000^4
152+
[1_234_567_891_234, 2_000_000_000_000],
153+
[1_234_567_891_234_567, 2_000_000_000_000_000],
154+
];
155+
156+
it('correctly rounds bytes values using base 10 round value', () => {
137157
for (let i = 0; i < expectedValues.length; ++i) {
138-
expect(findRoundBytesValueGreaterOrEqualTo(2 ** i - 1)).toBe(
139-
expectedValues[i]
140-
);
141-
}
142-
});
143-
144-
it('rounds large bytes values using base 2 round value', () => {
145-
for (let i = expectedValues.length; i < 40; ++i) {
146-
expect(findRoundBytesValueGreaterOrEqualTo(2 ** i - 1)).toBe(2 ** i);
158+
const [input, expected] = expectedValues[i];
159+
expect(findRoundBytesValueGreaterOrEqualTo(input)).toBe(expected);
147160
}
148161
});
149162
});

src/test/unit/marker-schema.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,9 @@ describe('marker schema formatting', function () {
357357
"bytes - 0B",
358358
"bytes - 10B",
359359
"bytes - 12B",
360-
"bytes - 121KB",
361-
"bytes - 118MB",
362-
"bytes - 115GB",
360+
"bytes - 123KB",
361+
"bytes - 123MB",
362+
"bytes - 123GB",
363363
"bytes - 0.000B",
364364
"integer - 0",
365365
"integer - 10",

src/utils/format-numbers.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export function formatGigaBytes(
180180
maxFractionalDigits: number = 2,
181181
precision: number = Infinity
182182
): string {
183-
const bytesPerGigabyte = 1024 ** 3;
183+
const bytesPerGigabyte = 1000 ** 3;
184184
if (precision === Infinity) {
185185
return (
186186
formatNumber(
@@ -210,7 +210,7 @@ export function formatMegaBytes(
210210
maxFractionalDigits: number = 2,
211211
precision: number = Infinity
212212
): string {
213-
const bytesPerMegabyte = 1024 ** 2;
213+
const bytesPerMegabyte = 1000 ** 2;
214214
if (precision === Infinity) {
215215
return (
216216
formatNumber(
@@ -240,7 +240,7 @@ export function formatKiloBytes(
240240
maxFractionalDigits: number = 2,
241241
precision: number = Infinity
242242
): string {
243-
const bytesPerKilobyte = 1024;
243+
const bytesPerKilobyte = 1000;
244244
if (precision === Infinity) {
245245
return (
246246
formatNumber(
@@ -274,14 +274,14 @@ export function formatBytes(
274274
// Use singles up to 10,000. I think 9,360B looks nicer than 9.36KB.
275275
// We use "0" for significantDigits because bytes will always be integers.
276276
return formatNumber(bytes, 0) + 'B';
277-
} else if (bytes < 1024 ** 2) {
277+
} else if (bytes < 1000 ** 2) {
278278
return formatKiloBytes(
279279
bytes,
280280
significantDigits,
281281
maxFractionalDigits,
282282
precision
283283
);
284-
} else if (bytes < 1024 ** 3) {
284+
} else if (bytes < 1000 ** 3) {
285285
return formatMegaBytes(
286286
bytes,
287287
significantDigits,
@@ -542,10 +542,10 @@ function _findRoundValueGreaterOrEqualTo(minValue: number): number {
542542

543543
export function findRoundBytesValueGreaterOrEqualTo(minValue: number): number {
544544
// Special case KB, MB, GB.
545-
if (minValue > 1024 && minValue <= 1024 ** 4) {
545+
if (minValue > 1000 && minValue <= 1000 ** 4) {
546546
for (const power of [1, 2, 3]) {
547547
for (const value of [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) {
548-
const number = value * 1024 ** power;
548+
const number = value * 1000 ** power;
549549
if (minValue <= number) {
550550
return number;
551551
}

0 commit comments

Comments
 (0)