1 <html> 2 <head> 3 <script> 4 5 // How many arrays to allocate. 6 var __n_arrays = 10; 7 // How many elements in each array 8 var __n_elements = 10 * 1000 * 1000; 9 // Touch one element every __touch_step elements. 10 var __touch_step = 5 * 1000; 11 var __total_allocation; 12 var __text_area = null; 13 14 function __initialize_bloat() { 15 __total_allocation = 0; 16 document.bloat = new Array(__n_arrays); 17 for (i = 0; i < __n_arrays; i++) { 18 document.bloat[i] = new Array(1); 19 } 20 __display_message("allocation was cleared"); 21 } 22 23 function __display_message(text) { 24 if (__text_area == null) { 25 __text_area = document.getElementById("text area"); 26 } 27 if (__text_area != null) { 28 __text_area.innerText = text; 29 } 30 } 31 32 function __bloat_array(i) { 33 var message = "allocated " 34 + __total_allocation / (1000000) + "M elements ..."; 35 if (i >= __n_arrays) { 36 message += " done" 37 } 38 __display_message(message); 39 if (i < __n_arrays) { 40 __total_allocation += __n_elements; 41 document.bloat[i] += new Array(__n_elements); 42 for (j = 0; j < __n_elements; j += __touch_step) { 43 document.bloat[i][j] = j; 44 } 45 setTimeout(function() {__bloat_array(i + 1);}, 10); 46 } 47 } 48 49 function __bloat() { 50 __bloat_array(0); 51 } 52 53 __initialize_bloat(); 54 __bloat(); 55 56 </script> 57 </head> 58 <body> 59 <center> 60 61 <div id="text area"> 62 No memory allocated yet. 63 </div> 64 65 </center> 66 </body> 67 </html> 68