Skip to content

Commit 6a77c61

Browse files
committed
saving.
1 parent 34d8ba7 commit 6a77c61

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

html/index.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ <h1>Uint8Array Base64 Benchmark</h1>
110110

111111
const orig = pseudoRandomBytes(s);
112112
const b64 = orig.toBase64();
113+
const b64WithLines = b64.replace(/(.{72})/g, '$1\n');
113114
const bytesDecoded = Math.floor(b64.length * 3 / 4);
114115
const bytesEncoded = orig.length;
115116

@@ -123,6 +124,10 @@ <h1>Uint8Array Base64 Benchmark</h1>
123124
Uint8Array.fromBase64(b64);
124125
}, { minSamples: 5 });
125126

127+
suite.add('Uint8Array.fromBase64() (line breaks)', function() {
128+
Uint8Array.fromBase64(b64WithLines);
129+
}, { minSamples: 5 });
130+
126131
suite.add('Uint8Array.toBase64()', function() {
127132
orig.toBase64();
128133
}, { minSamples: 5 });
@@ -141,18 +146,25 @@ <h1>Uint8Array Base64 Benchmark</h1>
141146
suite.on('complete', function() {
142147
// validation
143148
let valid = false;
149+
let validLines = false;
144150
try {
145151
const decoded = Uint8Array.fromBase64(b64);
146152
valid = decoded && decoded.length === orig.length;
147153
if (valid) {
148154
for (let i = 0; i < orig.length; i++) { if (decoded[i] !== orig[i]) { valid = false; break; } }
149155
}
156+
const decodedLines = Uint8Array.fromBase64(b64WithLines);
157+
validLines = decodedLines && decodedLines.length === orig.length;
158+
if (validLines) {
159+
for (let i = 0; i < orig.length; i++) { if (decodedLines[i] !== orig[i]) { validLines = false; break; } }
160+
}
150161
} catch (e) {
151162
resultsDiv.textContent += `\nValidation : error (${e.message})\n\n`;
152163
resolve();
153164
return;
154165
}
155166
resultsDiv.textContent += `\nValidation : ${valid ? 'OK' : 'MISMATCH'}\n`;
167+
resultsDiv.textContent += `Validation (lines): ${validLines ? 'OK' : 'MISMATCH'}\n`;
156168
const fastest = suite.filter('fastest').map('name');
157169
resultsDiv.textContent += `Fastest: ${fastest.join(', ')}\n\n`;
158170
resolve();

0 commit comments

Comments
 (0)