<commit_before>import Stats from "stats.js";

function makeStats() {
  // poor man's run once
  if (makeStats.stats) return makeStats.stats;
  makeStats.stats = new Stats();
  return makeStats.stats;
}

let reqId;
export const setupStats = config => {
  const stats = makeStats();
  if (config.debug) {
    document.body.appendChild(stats.dom);
    reqId = requestAnimationFrame(function loop() {
      stats.update();
      reqId = requestAnimationFrame(loop);
    });
  } else if (reqId) {
    cancelAnimationFrame(reqId);
    reqId = undefined;
    document.body.removeChild(stats.dom);
  }
};
<commit_msg>Fix stats reinitialization on reset<commit_after>import Stats from "stats.js";

function makeStats() {
  // poor man's run once
  if (makeStats.stats) return makeStats.stats;
  makeStats.stats = new Stats();
  return makeStats.stats;
}

let reqId;
export const setupStats = config => {
  const stats = makeStats();
  if (config.debug && !reqId) {
    document.body.appendChild(stats.dom);
    reqId = requestAnimationFrame(function loop() {
      stats.update();
      reqId = requestAnimationFrame(loop);
    });
  } else if (!config.debug && reqId) {
    cancelAnimationFrame(reqId);
    reqId = undefined;
    document.body.removeChild(stats.dom);
  }
};

{'fraction_non_alphanumeric': 0.13022888713496447, 'fraction_numerical': 0.0, 'mean_word_length': 3.661764705882353, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6051086', 'n_tokens_mistral': 397, 'n_tokens_neox': 390, 'n_words': 94}