File: buffer-base64-decode.js

package info (click to toggle)
nodejs 20.19.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 219,072 kB
  • sloc: cpp: 1,277,408; javascript: 565,332; ansic: 129,476; python: 58,536; sh: 3,841; makefile: 2,725; asm: 1,732; perl: 248; lisp: 222; xml: 42
file content (29 lines) | stat: -rw-r--r-- 660 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
'use strict';
const assert = require('assert');
const common = require('../common.js');

const bench = common.createBenchmark(main, {
  n: [32],
  size: [8 << 20],
});

function main({ n, size }) {
  const s = 'abcd'.repeat(size);
  const encodedSize = s.length * 3 / 4;
  // eslint-disable-next-line node-core/no-unescaped-regexp-dot
  s.match(/./);  // Flatten string.
  assert.strictEqual(s.length % 4, 0);
  const b = Buffer.allocUnsafe(encodedSize);
  b.write(s, 0, encodedSize, 'base64');

  let tmp;

  bench.start();

  for (let i = 0; i < n; i += 1)
    tmp = b.base64Write(s, 0, s.length);

  bench.end(n);

  assert.strictEqual(tmp, encodedSize);
}