<commit_before><style>
#options {
  position: absolute;
  background-color: #FFFFCC;
  display: none;
  font-family: "Courier New";
  font-size: 9pt;
  padding: 5px;
  border: 1px solid #CCCC88;
  z-index: 3;
}
</style>

<script>
// Round a number to the 1's place.
function formatNumber(str) {
  str += '';
  if (str == '0') {
    return 'N/A ';
  }
  var x = str.split('.');
  var x1 = x[0];
  var x2 = x.length > 1 ? '.' + x[1] : '';
  var regex = /(\d+)(\d{3})/;
  while (regex.test(x1)) {
    x1 = x1.replace(regex, '$1' + ',' + '$2');
  }
  return x1;
}

// Configuration and results are stored globally.
window.iterations = 10;
window.clearConnections = true;
window.clearCache = true;
window.results = {};
window.results.data = new Array();
window.testUrl = "";
window.windowId = 0;

function show_options() {
  chrome.tabs.getSelected(null, function(tab) {
    window.testUrl = tab.url;
    var tabs = chrome.extension.getExtensionTabs();
    if (tabs && tabs.length) {
      tabs[0].setUrl(testUrl);
      var optionsUrl = chrome.extension.getURL("options.html");
      chrome.tabs.getAllInWindow(null, function(all) {
        for (var i = 0; i < all.length; i++) {
          if (all[i].url == optionsUrl) {
            chrome.tabs.update(all[i].id, {selected: true });
            return;
          }
        }
      });
    } else {
      chrome.tabs.create({"url":"options.html"});
    }
  });
}

chrome.browserAction.onClicked.addListener(show_options);

function Benchmark() {
  var runCount_ = 0;
  var count_;
  var totalTime_;
  var lastWin_;
  var me_ = this;
  var current_;
  var initialReadBytes_;
  var initialWriteBytes_;

  // Start a test run
  this.start = function(url) {
    // Check if a run is already in progress.
    if (me_.isRunning()) {
      return;
    }

    console.log("Starting test for url: " + url);

    runCount_ = window.iterations;
    count_ = 0;
    totalTime_ = 0;
    lastWin_ = 0;

    current_ = {};
    current_.url = url;
    current_.docLoadResults = new Array();  // times to docload
    current_.paintResults = new Array();    // times to paint
    current_.totalResults = new Array();    // times to complete load
    initialReadBytes = chrome.benchmarking.counter("tcp.read_bytes");
    initialWriteBytes = chrome.benchmarking.counter("tcp.write_bytes");

    me_.runPage();
  }

  // Is the benchmark currently in progress.
  this.isRunning = function() {
    return runCount_ > 0;
  }

  // Called when the test run completes.
  this.finish = function() {
    lastWin_.close();
    lastWin_ = 0;

    // Record some more stats.
    current_.bytesRead = chrome.benchmarking.counter("tcp.read_bytes") -
                          initialReadBytes;
    current_.bytesWritten = chrome.benchmarking.counter("tcp.write_bytes") -
                            initialWriteBytes;
    current_.totalTime = totalTime_;

    // push the result
    window.results.data.push(current_);
    current_ = 0;
  }

  // Update the UI after a test run.
  this.displayResults = function() {
    var score = 0;
    if (count_ > 0) {
      score = totalTime_ / count_;
      var text = score.toFixed(1) + "ms avg";
      chrome.browserAction.setTitle({"title": text});
    }
    if (runCount_) {
      chrome.browserAction.setBadgeText({"text": "" + runCount_});
      chrome.browserAction.setBadgeBackgroundColor({"color": [255, 0, 0, 255]});
    } else {
      chrome.browserAction.setBadgeText({"text": "" + score.toFixed()});
      chrome.browserAction.setBadgeBackgroundColor({"color": [0, 255, 0, 255]});
      var tabs = chrome.extension.getExtensionTabs();
      if (tabs && tabs.length) {
        tabs[0].location.reload();
      }
    }
  }

  // Run a single page in the benchmark
  this.runPage = function() {
    if (window.clearCache) {
      chrome.benchmarking.clearCache();
    }
    if (window.clearConnections) {
      chrome.benchmarking.closeConnections();
    }

    if (lastWin_) {
      lastWin_.location = current_.url;
    } else {
      lastWin_ = window.open(current_.url);
    }
  }

  // Called when a page finishes loading.
  this.pageFinished = function(csi) {
    var docLoadTime =
        Math.round((csi.finishDocumentLoadTime - csi.startLoadTime) * 1000.0);
    var paintTime =
        Math.round((csi.firstPaintTime - csi.startLoadTime) * 1000.0);
    var totalTime =
        Math.round((csi.finishLoadTime - csi.startLoadTime) * 1000.0);
<commit_msg>The benchmark was broken in multi-process mode. Turns out that the extension API changed such that scripts don't run in pages which are hosted in the extension process (like this one).<commit_after><style>
#options {
  position: absolute;
  background-color: #FFFFCC;
  display: none;
  font-family: "Courier New";
  font-size: 9pt;
  padding: 5px;
  border: 1px solid #CCCC88;
  z-index: 3;
}
</style>

<script>
// Round a number to the 1's place.
function formatNumber(str) {
  str += '';
  if (str == '0') {
    return 'N/A ';
  }
  var x = str.split('.');
  var x1 = x[0];
  var x2 = x.length > 1 ? '.' + x[1] : '';
  var regex = /(\d+)(\d{3})/;
  while (regex.test(x1)) {
    x1 = x1.replace(regex, '$1' + ',' + '$2');
  }
  return x1;
}

// Configuration and results are stored globally.
window.iterations = 10;
window.clearConnections = true;
window.clearCache = true;
window.results = {};
window.results.data = new Array();
window.testUrl = "";
window.windowId = 0;

function show_options() {
  chrome.tabs.getSelected(null, function(tab) {
    window.testUrl = tab.url;
    var tabs = chrome.extension.getExtensionTabs();
    if (tabs && tabs.length) {
      tabs[0].setUrl(testUrl);
      var optionsUrl = chrome.extension.getURL("options.html");
      chrome.tabs.getAllInWindow(null, function(all) {
        for (var i = 0; i < all.length; i++) {
          if (all[i].url == optionsUrl) {
            chrome.tabs.update(all[i].id, {selected: true });
            return;
          }
        }
      });
    } else {
      chrome.tabs.create({"url":"options.html"});
    }
  });
}

chrome.browserAction.onClicked.addListener(show_options);

function Benchmark() {
  var runCount_ = 0;
  var count_;
  var totalTime_;
  var lastWin_;
  var me_ = this;
  var current_;
  var initialReadBytes_;
  var initialWriteBytes_;

  // Start a test run
  this.start = function(url) {
    // Check if a run is already in progress.
    if (me_.isRunning()) {
      return;
    }

    console.log("Starting test for url: " + url);

    runCount_ = window.iterations;
    count_ = 0;
    totalTime_ = 0;
    lastWin_ = 0;

    current_ = {};
    current_.url = url;
    current_.docLoadResults = new Array();  // times to docload
    current_.paintResults = new Array();    // times to paint
    current_.totalResults = new Array();    // times to complete load
    initialReadBytes = chrome.benchmarking.counter("tcp.read_bytes");
    initialWriteBytes = chrome.benchmarking.counter("tcp.write_bytes");

    me_.runPage();
  }

  // Is the benchmark currently in progress.
  this.isRunning = function() {
    return runCount_ > 0;
  }

  // Called when the test run completes.
  this.finish = function() {
    chrome.tabs.remove(lastWin_.id);
    lastWin_ = 0;

    // Record some more stats.
    current_.bytesRead = chrome.benchmarking.counter("tcp.read_bytes") -
                          initialReadBytes;
    current_.bytesWritten = chrome.benchmarking.counter("tcp.write_bytes") -
                            initialWriteBytes;
    current_.totalTime = totalTime_;

    // push the result
    window.results.data.push(current_);
    current_ = 0;
  }

  // Update the UI after a test run.
  this.displayResults = function() {
    var score = 0;
    if (count_ > 0) {
      score = totalTime_ / count_;
      var text = score.toFixed(1) + "ms avg";
      chrome.browserAction.setTitle({"title": text});
    }
    if (runCount_) {
      chrome.browserAction.setBadgeText({"text": "" + runCount_});
      chrome.browserAction.setBadgeBackgroundColor({"color": [255, 0, 0, 255]});
    } else {
      chrome.browserAction.setBadgeText({"text": "" + score.toFixed()});
      chrome.browserAction.setBadgeBackgroundColor({"color": [0, 255, 0, 255]});
      var tabs = chrome.extension.getExtensionTabs();
      if (tabs && tabs.length) {
        tabs[0].location.reload();
      }
    }
  }

  // Run a single page in the benchmark
  this.runPage = function() {
    if (window.clearCache) {
      chrome.benchmarking.clearCache();
    }
    if (window.clearConnections) {
      chrome.benchmarking.closeConnections();
    }

    if (lastWin_) {
      chrome.tabs.update(lastWin_.id, {"url": current_.url});
    } else {
      chrome.tabs.create({"url": current_.url},
                         function(tab) { lastWin_ = tab; });
    }
  }

  // Called when a page finishes loading.
  this.pageFinished = function(csi) {
    var docLoadTime =
        Math.round((csi.finishDocumentLoadTime - csi.startLoadTime) * 1000.0);
    var paintTime =
        Math.round((csi.firstPaintTime - csi.startLoadTime) * 1000.0);
    var totalTime =
        Math.round((csi.finishLoadTime - csi.startLoadTime) * 1000.0);

{'fraction_non_alphanumeric': 0.14348350323358544, 'fraction_numerical': 0.014688150827578647, 'mean_word_length': 2.642315369261477, 'pattern_counts': {'":': 14, '<': 11, '<?xml version=': 0, '>': 15, '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': '6274543', 'n_tokens_mistral': 3138, 'n_tokens_neox': 2937, 'n_words': 684}