c# - Help me optimize this average calculation snippet -


Is this snippet possible?

The first sample and previous sample is part of the array that I am interested in this walk. This happens when this gap reaches up to 3000, I get noticeable recession. The _Average array can contain 6-60 million in value.

I use it after the minimum and maxY are completed.

int miny = Int32.MaxValue; Int maxY = Int32.MinValue; Int Y = 0; Int sample = first sample + 1; While (sample & lt; = lastSample) {Y = _Average [sample]; Minwai = Math Pisces (Y, Minne); Max Y = Math Max (Y, Max); Sample ++; } _Average [sample] expression is a major constraint, because it is a vested limit Examine each iteration on an indicator in the "_Average" array (and the unsecured keyword). Then avoid calling any work, so get rid of the monastery. Call Min / Max and check it for yourself.

Without any compiler on my hands, I think that should look like this:

  unsafe {fixed (int * paverage = _average) {int * p = paverage + FirstSample + 1; (Integer sample = first sample + 1; sample & lt; = final sample; sample ++) {if (* p & lt; minY) minY = * p; If (* p & gt; maxY) maxY = * p; P ++; Ultimately, since "sample" is not actually used in the loop, you can convert it to the loop variable, which is counted as zero, so that loop termination can be checked against constant (zero) instead of one variable is done. 


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -