<commit_before>'use strict';

// This calculates time intervals, in order to do performance monitoring
// Concepts:
//   - a `label` is a measurements name
//   - a `category` is the namespace of a label. Default is "default"
//   - a label can have several `measures`
//     Each call to startPerf() will create a new measure, which is assigned
//   - each measure can be stopped and restarted by calling `stopPerf()`
//     and `restartPerf()`
// API:
//   - `const measure = startPerf('label', 'category');` starts a measure
//   - `const newMeasure = stopPerf(measure);` stops a measure
// Notice that a new measure is returned after each call, the passed measure
// is not modified.

const { hrtime } = process;

const { throwError } = require('../error');

const { CATEGORIES, DEFAULT_CATEGORY } = require('./constants');

// Start a new measure
const startPerf = function (label, category = DEFAULT_CATEGORY) {
  validateOptions({ label, category });

  // `hrtime()` is more precise that `Date.now()`
  const pending = hrtime();
  return { pending, label, category };
};

const validateOptions = function ({ label, category }) {
  if (typeof label !== 'string') {
    const message = 'Performance label must be a string';
    throwError(message, { reason: 'UTILITY_ERROR' });
  }

  if (typeof category !== 'string') {
    const message = 'Performance category must be a string';
    throwError(message, { reason: 'UTILITY_ERROR' });
  }

  if (!CATEGORIES.includes(category)) {
    const message = `Unknown performance category: '${category}'`;
    throwError(message, { reason: 'UTILITY_ERROR' });
  }
};

const stopPerf = function ({ pending, duration: oDur = 0, label, category }) {
  if (pending === undefined) {
    const message = 'Must call \'restartPerf()\' before calling \'stopPerf()\'';
    throwError(message, { reason: 'UTILITY_ERROR' });
  }

  // Substracts the current time with the previous time
  const [secs, nanoSecs] = hrtime();
  const [lastSecs, lastNanoSecs] = pending;
  const newDuration = (secs - lastSecs) * 10 ** 9 + (nanoSecs - lastNanoSecs);
  const duration = oDur + newDuration;
  return { duration, label, category };
};

module.exports = {
  startPerf,
  stopPerf,
};
<commit_msg>Remove dead code<commit_after>'use strict';

// This calculates time intervals, in order to do performance monitoring
// Concepts:
//   - a `label` is a measurements name
//   - a `category` is the namespace of a label. Default is "default"
//   - a label can have several `measures`
//     Each call to startPerf() will create a new measure, which is assigned
//   - each measure can be stopped and restarted by calling `stopPerf()`
//     and `restartPerf()`
// API:
//   - `const measure = startPerf('label', 'category');` starts a measure
//   - `const newMeasure = stopPerf(measure);` stops a measure
// Notice that a new measure is returned after each call, the passed measure
// is not modified.

const { hrtime } = process;

const { throwError } = require('../error');

const { CATEGORIES, DEFAULT_CATEGORY } = require('./constants');

// Start a new measure
const startPerf = function (label, category = DEFAULT_CATEGORY) {
  validateOptions({ label, category });

  // `hrtime()` is more precise that `Date.now()`
  const pending = hrtime();
  return { pending, label, category };
};

const validateOptions = function ({ label, category }) {
  if (typeof label !== 'string') {
    const message = 'Performance label must be a string';
    throwError(message, { reason: 'UTILITY_ERROR' });
  }

  if (typeof category !== 'string') {
    const message = 'Performance category must be a string';
    throwError(message, { reason: 'UTILITY_ERROR' });
  }

  if (!CATEGORIES.includes(category)) {
    const message = `Unknown performance category: '${category}'`;
    throwError(message, { reason: 'UTILITY_ERROR' });
  }
};

const stopPerf = function ({ pending, label, category }) {
  if (pending === undefined) {
    const message = 'Must call \'restartPerf()\' before calling \'stopPerf()\'';
    throwError(message, { reason: 'UTILITY_ERROR' });
  }

  // Substracts the current time with the previous time
  const [secs, nanoSecs] = hrtime();
  const [lastSecs, lastNanoSecs] = pending;
  const duration = (secs - lastSecs) * 10 ** 9 + (nanoSecs - lastNanoSecs);
  return { duration, label, category };
};

module.exports = {
  startPerf,
  stopPerf,
};

{'fraction_non_alphanumeric': 0.13898382319434952, 'fraction_numerical': 0.001594896331738437, 'mean_word_length': 3.6356916578669485, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5589014', 'n_tokens_mistral': 1337, 'n_tokens_neox': 1305, 'n_words': 455}