2
我用Javascript編寫了一個程序,它從文件中讀取數字,對它們進行排序,然後將它們寫回到文件中。但是我無法找到合適的方法或工具來獲取內存使用情況(例如Runtime.getRuntime()。totalMemory() - Runtime.getRuntime()。freeMemory();在java中)。如果有人可以請給我一個領導,我會很感激。在javascript中計算內存使用情況
這是代碼。
<html>
<script>
var oRequest;
var data=new Array();
var b= new Array();
var j
var k;
var temp;
var temp1;
if(document.all) {
oRequest = new ActiveXObject("Microsoft.XMLHTTP")
}
else {
oRequest = new XMLHttpRequest();
}
oRequest.open("GET", "file:///C:/numbers.txt", true);
oRequest.send(null);
numbers= oRequest.responseText.split("\n");
for (var i = 0;i<(numbers.length-1);i++)
{
numbers[i] = parseInt(numbers[i],10);
}
var d = new Date();
var start = d.getTime();
for(var i=0;i<numbers.length;i++)
{
for(j=0;j<(numbers.length-1);j++)
{
if(numbers[j]>numbers[j+1])
{
temp=numbers[j+1];
numbers[j+1] = numbers[j];
numbers[j] = temp;
}
}}
var g = new Date();
var end =g.getTime();
var diff=(end-start);
</script>
<script>
function WriteFile()
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
var fh = fso.CreateTextFile("C:\\BubbleJS.txt", true);
for(i=0;i<5000;i++)
{
fh.WriteLine(numbers[i]);
}
fh.WriteLine("\n");
fh.WriteLine("The time required for sorting is "+diff+" Milliseconds");
fh.Close();
}
</script>
<form>
<body background="Bubble.png">
<h1> </h1>
<input type="button" onClick='alert("Directing to Home Page"); window.location = "Home Page.html"' value="Back to Home Page">
<input type="button" onClick=WriteFile(); value="Begin Sorting!"
style="width: 174px; margin-left: 0px">
</form>
</html>
[JQuery或JavaScript查找內存使用情況的頁面]的可能重複(http://stackoverflow.com/questions/2530228/jquery-or-javascript-to-find-memory-usage-of-page) – ManseUK 2012-03-19 14:21:12