# Tag Archives: variance

## Quick and dirty tests and misleading results

Today this blog post popped up on my desktop. It describes a quick attempt to outperform the variance function of our friend library MathNet.Numerics by utilizing the Task Parallel Library from within F#. It obviously worked out – by a factor of 10! Since this seemed strange to me, I couldn’t resist to make my own (very quick and dirty) comparison.

The code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ILNumerics;
using MathNet;
using MathNet.Numerics.Statistics;
using System.Diagnostics;

namespace ConsoleApplication6 {
class Program : ILMath {
static void Main(string[] args) {
long ms = 0;
int n = 10000000;
int it = 100;

ILArray<double> A = randn(1,n);
Stopwatch sw = new Stopwatch();
for (int i = 0; i < it; i++) {
sw.Restart();
ILArray<double> B = var(A);
sw.Stop();
ms += sw.ElapsedMilliseconds;
}
Console.WriteLine("ILNumerics needed: {0} ms",ms/(float)it);

double[] storage = A.ToArray();
ms = 0;
for (int i = 0; i < it; i++) {
sw.Restart();
double a = Statistics.Variance(storage);
sw.Stop();
ms += sw.ElapsedMilliseconds;
}
Console.WriteLine("Mathnet.Numerics needed: {0} ms", ms / (float)it);

ILNumerics needed: 101,87 ms