%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/vacivi36/vittasync.vacivitta.com.br/vittasync/node/benchmark/fs/
Upload File :
Create Path :
Current File : /home/vacivi36/vittasync.vacivitta.com.br/vittasync/node/benchmark/fs/readFileSync.js

'use strict';

const common = require('../common.js');
const fs = require('fs');

const bench = common.createBenchmark(main, {
  encoding: ['undefined', 'utf8'],
  path: ['existing', 'non-existing'],
  hasFileDescriptor: ['true', 'false'],
  n: [1e4],
});

function main({ n, encoding, path, hasFileDescriptor }) {
  const enc = encoding === 'undefined' ? undefined : encoding;
  let file;
  let shouldClose = false;

  if (hasFileDescriptor === 'true') {
    shouldClose = path === 'existing';
    file = path === 'existing' ? fs.openSync(__filename) : -1;
  } else {
    file = path === 'existing' ? __filename : '/tmp/not-found';
  }
  bench.start();
  for (let i = 0; i < n; ++i) {
    try {
      fs.readFileSync(file, enc);
    } catch {
      // do nothing
    }
  }
  bench.end(n);
  if (shouldClose) {
    fs.closeSync(file);
  }
}

Zerion Mini Shell 1.0