Thursday, 15 September 2011

c# - How efficient is .NET framework's DataVisualization.Charting.StatisticFormula.Mean() versus just creating a list, enumerating, summation and dividing? -



c# - How efficient is .NET framework's DataVisualization.Charting.StatisticFormula.Mean() versus just creating a list, enumerating, summation and dividing? -

i attempted utilize ilspy take @ system.windows.forms.datavisualization.dll @ function system.windows.forms.datavisualization.charting.statisticformula.mean() , doesn't appear able render contents.

i curious, function more efficient @ producing mean writing own mean function, such follows:

public static double mean(this ienumerable<double> values) { double sum = 0; int count = 0; foreach(double d in values) { sum += d; count++; } homecoming sum / count; }

i going dealing 3 1000000 or more members.

[update]

during testing, linq's ienumerable.average() seems efficient on old dual core workstation, processing list<int> of 87000 members in 0.0011471 seconds. much more efficient thought be:

var s3 = stopwatch.startnew(); double average1 = daysamplevalues.average(); s3.stop(); timespan totaltime = s3.elapsed; // = 0.0011471 seconds

average o(n) operation, there's not much can optimize within c#. try parallelizing with:

values.asparallel().average();

but overhead of parallelization may more benefit of running multiple threads simultaneously.

the other optimization replace count measurement phone call values.count(). if underlying info construction list or array count() o(1) , may save bit of computing time.

in case, way true reply measure it. seek each way , see 1 faster. if possible, seek them on different scheme architectures see benefit of multiple-cores, more memory, etc.

c# performance mean

No comments:

Post a Comment