Regarding calculating memory and cpu usage

Oct 16 2006 9:21 AM

hi dear

i am trying to calculate the total amount of memory and cpu used while using string and stringbuilder.

i am trying this way ...

calling a method in one button click and writin to response.

 Process myprocess=Process.GetCurrentProcess();
 string str=null;
 for (int i=0;i<=10000;i++)
 {
  str+="Hello1";
  str+="Hello2";
 }
 Response.Write("using string : "+myprocess.WorkingSet.ToString()+"</br>");

and calling another method on another button click and writing to response.

Process myprocess=Process.GetCurrentProcess();
 StringBuilder str=new StringBuilder();
 for (int i=0;i<=10000;i++)
 {
  str.Append("Hello1");
  str.Append("Hello2");    
 }
 Response.Write("using stringbuilder : "+myprocess.WorkingSet.ToString()+"</br>");


but i am not getting the appropriate answer as it is showing the stringuilder is using much memory then string...

i have calculated the total time using two date time variables initialising them before starting and end of loop and then subtracting and getting the milliseconds of difference in between them. one more thing that i am calling both the functions after restarting the page.

please help out me guys, i need the solution of this problem very urgently!!!!!!!!!!!!!!!!!!!!!!!!1
regards
vishal sharma