11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst assert = require('assert'); 31cb0ef41Sopenharmony_ciconst common = require('../common.js'); 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciconst bench = common.createBenchmark(main, { 61cb0ef41Sopenharmony_ci n: [32], 71cb0ef41Sopenharmony_ci size: [8 << 20], 81cb0ef41Sopenharmony_ci}); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_cifunction main({ n, size }) { 111cb0ef41Sopenharmony_ci const s = 'abcd'.repeat(size); 121cb0ef41Sopenharmony_ci const encodedSize = s.length * 3 / 4; 131cb0ef41Sopenharmony_ci // eslint-disable-next-line node-core/no-unescaped-regexp-dot 141cb0ef41Sopenharmony_ci s.match(/./); // Flatten string. 151cb0ef41Sopenharmony_ci assert.strictEqual(s.length % 4, 0); 161cb0ef41Sopenharmony_ci const b = Buffer.allocUnsafe(encodedSize); 171cb0ef41Sopenharmony_ci b.write(s, 0, encodedSize, 'base64'); 181cb0ef41Sopenharmony_ci bench.start(); 191cb0ef41Sopenharmony_ci for (let i = 0; i < n; i += 1) b.base64Write(s, 0, s.length); 201cb0ef41Sopenharmony_ci bench.end(n); 211cb0ef41Sopenharmony_ci} 22