1'use strict'; 2const assert = require('assert'); 3const common = require('../common.js'); 4 5const bench = common.createBenchmark(main, { 6 n: [32], 7 size: [8 << 20] 8}); 9 10function main({ n, size }) { 11 const s = 'abcd'.repeat(size); 12 const encodedSize = s.length * 3 / 4; 13 // eslint-disable-next-line node-core/no-unescaped-regexp-dot 14 s.match(/./); // Flatten string. 15 assert.strictEqual(s.length % 4, 0); 16 const b = Buffer.allocUnsafe(encodedSize); 17 b.write(s, 0, encodedSize, 'base64'); 18 bench.start(); 19 for (let i = 0; i < n; i += 1) b.base64Write(s, 0, s.length); 20 bench.end(n); 21} 22