• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1function alloc(sizeMB, randomRatio) {
2  const FLOAT64_BYTES = 8;
3  const MB = 1024 * 1024;
4  const total_count = sizeMB* MB / FLOAT64_BYTES;
5  const random_count = total_count * randomRatio;
6  // Random array is uncompressable.
7  let random_array = new Float64Array(random_count);
8  for (let i = 0; i < random_array.length; i++) {
9    random_array[i] = Math.random();
10  }
11  // Constant array is compressable.
12  const const_count = total_count * (1 - randomRatio);
13  let const_array = new Float64Array(const_count);
14  for (let i = 0; i < const_array.length; i++) {
15    const_array[i] = 1;
16  }
17  return [random_array, const_array];
18}
19$(document).ready(function() {
20  var url = new URL(window.location.href);
21  var allocMB = parseInt(url.searchParams.get("alloc"));
22  if (isNaN(allocMB))
23    allocMB = 800;
24  var randomRatio = parseFloat(url.searchParams.get("ratio"));
25  if (isNaN(randomRatio))
26    randomRatio = 0.666
27
28  var startTime = new Date();
29  // Assigns the content to docuement to avoid optimization of unused data.
30  document.out = alloc(allocMB, randomRatio);
31  var ellapse = (new Date() - startTime) / 1000;
32  // Shows the loading time for manual test.
33  $("#display").text(`Allocating ${allocMB} MB takes ${ellapse} seconds`);
34});
35