Jump to content
  • Advertisement
Sign in to follow this  
Plerion

[C#] Strange overhead

This topic is 2893 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello!

In order to imrpove the performance of my application im measuring some times and ive found some weird things. Here is an example:

public ADTTile(byte[] strm)
{
System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
watch.Start();
fileBuffer = new Unmanaged.FileBuffer(strm);
MS = watch.ElapsedMilliseconds;
}



MS is set to a value between 10 and 15. If i change the code to that:

public ADTTile(byte[] strm)
{
fileBuffer = new Unmanaged.FileBuffer(strm);
}



and measure the time from "outside" like that:

System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
watch.Start();
Adt.ADTTile tile = new Adt.ADTTile(data));
MessageBox.Show(watch.ElapsedMilliseconds.ToString());



I get times between 180 and 250. Where does that huge overhead come from and is there a way to reduce that?

Any tip or trick is appreciated.

Greetings
Plerion

Share this post


Link to post
Share on other sites
Advertisement
-This sounds like premature optimization.
-Measuring only one run of the function is meaningless in real-world scenarios.
-.net (nor majority of operating systems) is not designed for real-time systems where millisecond accuracy over high-level operations is critical.
-You can use a profiler to see where the time is spent.

That said:

The .net garbage collector is invoked when you allocate certain amounts of memory, to empty unused memory and defragment it for future allocations. Your "ADTTile" class probably crosses this allocation limit. This is the price you pay in not having to manually manage your memory. To overcome this problem (if it is an actual problem to begin with), adjust your allocation strategy appropriately so that you preallocate critical objects before you need them in the middle of high-performance code.

If this does not seem like the cause, run a profiler anyway to see the program flow details.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!