Main Site Documentation

Array.Copy vs Utility.ExtractRangeFromArray


#1

Hi,

I’ve read somewhere that Utility.ExtractRangeFromArray or Array.Copy is implemented in native code
(Can’t remember which one or if it was both)

Anyway, when performance is really important (and an issue) is one of these faster than the other
to get a number of bytes from an array?


#2

The best thing to do is to make a small program to test the performance of each in your usage case. Just save the value of the tick counter, do an array copy 100 times and then subtract the saved the starting ticks form current ticks to get time elapsed.

One trick is to choose a number of iterations that takes long enough for you to the elapsed time but not so many that you are making the GC kick in in the middle or that you run out of memory. I have found around a 100 iterations works well.


#3

I’ll give it a try, thnx