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 = 1000; 11 var __bloat_interval_ms = 100; 12 var __text_area = null; 13 var __start_time; 14 15 function __initialize_bloat() { 16 __total_allocation = 0; 17 document.bloat = new Array(__n_arrays); 18 for (i = 0; i < __n_arrays; i++) { 19 document.bloat[i] = new Array(1); 20 } 21 __display_message("allocation was cleared"); 22 } 23 24 function __display_message(text) { 25 if (__text_area == null) { 26 __text_area = document.getElementById("text area"); 27 } 28 if (__text_area != null) { 29 __text_area.innerText = text; 30 } 31 } 32 33 function __bloat_array(i) { 34 if (i < __n_arrays) { 35 document.bloat[i] += new Array(__n_elements); 36 for (j = 0; j < __n_elements; j += __touch_step) { 37 document.bloat[i][j] = j; 38 } 39 setTimeout(function() {__bloat_array(i + 1);}, __bloat_interval_ms); 40 } 41 var message = "allocated " 42 + i + " arrays of size " + __n_elements / (1000 * 1000) + "M\n"; 43 if (i >= __n_arrays) { 44 message += "done, elapsed time = " + 45 ((new Date).getTime() - __start_time) / 1000.0 + " seconds"; 46 } 47 __display_message(message); 48 } 49 50 function __bloat() { 51 __start_time = (new Date).getTime(); 52 __bloat_array(0); 53 } 54 55 __initialize_bloat(); 56 __bloat(); 57 58 </script> 59 </head> 60 <body> 61 <center> 62 63 <div id="text area"> 64 No memory allocated yet. 65 </div> 66 67 </center> 68 </body> 69 </html> 70