<commit_before>var proposals = [
  require("./native_1d.js"),
  require("./typed_1d.js"),
  require("./object_array.js"),
  require("./object_flat.js"),
  require("./object_flat_no_offset.js"),
  require("./multi_native.js"),
  require("./multi_typed.js"),
  require("./multi_cont.js"),
  require("./numeric_simple.js"),
  require("./numeric_pointwise.js"),
  require("./ndarrayops.js"),
  require("./cwise.js")
];

function padTo(str, nchars, where) {
  if (str.length < nchars) {
    if (where === "left") // left pad
      str = (new Array(nchars + 1 - str.length)).join(' ') + str;
    else // right pad
      str += (new Array(nchars + 1 - str.length)).join(' ');
  }

  return str;
}

function doTest(nx, ny, nz) {
  console.log("Running experiment with dimensions =", nx, "x", ny, "x", nz);
  for(var i=0; i<proposals.length; ++i) {
    var prop = proposals[i],
        bench = prop.benchmark,
        A, B, C, initTime, runTime;

    initTime = Date.now();
    A = prop.initArray(nx, ny, nz);
    B = prop.initArray(nx, ny, nz);

    if (bench.length === 7) {
      C = prop.initArray(nx, ny, nz);
      initTime = Date.now() - initTime;
      runTime = Date.now();
      for(var j=0; j<16; ++j) {
        bench(A, B, C, nx, ny, nz, 16);
      }
    } else {
      initTime = Date.now() - initTime;
      runTime = Date.now();
      for(var j=0; j<16; ++j) {
        bench(A, B, nx, ny, nz, 16);
      }
    }
    runTime = Date.now() - runTime;

    console.log("   Proposal #", padTo((i + 1).toString(), 2),
                padTo(prop.prop_name, 40),
                "Total Init =", padTo(initTime.toString(), 6, "left") + "ms",
                " Execution =", padTo(runTime.toString(), 6, "left") + "ms");
  }
}

doTest(16, 16, 16);
doTest(64, 64, 64);

doTest(512, 512, 4);
doTest(512, 4, 512);
doTest(4, 512, 512);

doTest(2, 2, 2048);
doTest(2048, 2, 2);<commit_msg>wrap benchmarks in try..catch for modules that may try to allocate more memory than is allowed<commit_after>var proposals = [
  require("./native_1d.js"),
  require("./typed_1d.js"),
  require("./object_array.js"),
  require("./object_flat.js"),
  require("./object_flat_no_offset.js"),
  require("./multi_native.js"),
  require("./multi_typed.js"),
  require("./multi_cont.js"),
  require("./numeric_simple.js"),
  require("./numeric_pointwise.js"),
  require("./ndarrayops.js"),
  require("./cwise.js")
];

function padTo(str, nchars, where) {
  if (str.length < nchars) {
    if (where === "left") // left pad
      str = (new Array(nchars + 1 - str.length)).join(' ') + str;
    else // right pad
      str += (new Array(nchars + 1 - str.length)).join(' ');
  }

  return str;
}

function doTest(nx, ny, nz) {
  console.log("Running experiment with dimensions =", nx, "x", ny, "x", nz);
  for(var i=0; i<proposals.length; ++i) {
    var prop = proposals[i],
        bench = prop.benchmark,
        A, B, C, initTime, runTime;

    try {
      initTime = Date.now();
      A = prop.initArray(nx, ny, nz);
      B = prop.initArray(nx, ny, nz);

      if (bench.length === 7) {
        C = prop.initArray(nx, ny, nz);
        initTime = (Date.now() - initTime) + "ms";
        runTime = Date.now();
        for(var j=0; j<16; ++j) {
          bench(A, B, C, nx, ny, nz, 16);
        }
      } else {
        initTime = (Date.now() - initTime) + "ms";
        runTime = Date.now();
        for(var j=0; j<16; ++j) {
          bench(A, B, nx, ny, nz, 16);
        }
      }
      runTime = (Date.now() - runTime) + "ms";
    } catch (e) {
      initTime = runTime = "FAILED";
    }

    console.log("   Proposal", "#" + padTo((i + 1).toString(), 2),
                padTo(prop.prop_name, 40),
                "Total Init =", padTo(initTime.toString(), 8, "left"),
                " Execution =", padTo(runTime.toString(), 8, "left"));
  }
}

doTest(16, 16, 16);
doTest(64, 64, 64);

doTest(512, 512, 4);
doTest(512, 4, 512);
doTest(4, 512, 512);

doTest(2, 2, 2048);
doTest(2048, 2, 2);
{'fraction_non_alphanumeric': 0.20453972257250946, 'fraction_numerical': 0.03379571248423707, 'mean_word_length': 2.525333333333333, 'pattern_counts': {'":': 0, '<': 11, '<?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': '7168413', 'n_tokens_mistral': 1608, 'n_tokens_neox': 1491, 'n_words': 341}