1

I've got two methods. I want to test its performance.

The time of its work I can get with stopwatch. But how to get information about RAM?Are there any classes for it?

Or I will have to get it from task manager manually?(stop program+run tm+continue program)

Eric J.
  • 147,927
  • 63
  • 340
  • 553
  • 1
    possible duplicate of [Poll C# app's memory usage at runtime?](http://stackoverflow.com/questions/463595/poll-c-sharp-apps-memory-usage-at-runtime) – digEmAll Mar 20 '12 at 22:36
  • Have a look at the dupe I posted in the previous comment. Or also you can use a memory profiler that gives you even much more infos. – digEmAll Mar 20 '12 at 22:37

2 Answers2

3

You're looking for

Process.GetCurrentProcess().WorkingSet64
SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • What's the difference between that, Process.PagedMemorySize64 and Process.PrivateMemorySize64 (the accepted answer and alternate suggestion from http://stackoverflow.com/questions/463595/poll-c-sharp-apps-memory-usage-at-runtime)? – Eric J. Mar 20 '12 at 22:38
  • @EricJ: I'm embarrassed to admit that I have no idea. – SLaks Mar 21 '12 at 05:33
2

Check out Jon Skeet's blog on similar subject - http://msmvps.com/blogs/jon_skeet/archive/2011/04/05/of-memory-and-strings.aspx.

Basically use GC.GetTotalMemory

  long before = GC.GetTotalMemory(true);
    // do something 
  long after = GC.GetTotalMemory(true);

  Console.WriteLine("Diff:{0}" after - before;);

Note that TaskManager shows how much memory process is allocated, you want to see how much memory CLR is allocated for alive objects at particular point.

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179