Skip to content

Instantly share code, notes, and snippets.

@manofstick
Created December 22, 2018 05:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manofstick/69b489394a172d49f8f6feed3a3ce505 to your computer and use it in GitHub Desktop.
Save manofstick/69b489394a172d49f8f6feed3a3ce505 to your computer and use it in GitHub Desktop.
LinqOptimizer's CartLinq
using System;
using System.Diagnostics;
#if manofstick_test_chainlinq
using System.ChainLinq;
#else
using System.Linq;
#endif
class Program
{
public static void Main()
{
var sw = new Stopwatch();
var rnd = new Random(08041988);
foreach (var Count in new[] { 0, 10, 100, 10000, 1000000 })
{
var values = Enumerable.Range(1, Count).Select(x => rnd.NextDouble()).ToArray();
var dim1 = values.Take(values.Length / 10).ToArray();
var dim2 = values.Take(20).ToArray();
sw.Restart();
var sum = 0.0;
for (var i = 0; i < 100000000 / (Count + 1); ++i)
{
sum += (from x in dim1
from y in dim2
select x * y).Sum();
}
var time = sw.ElapsedMilliseconds;
Console.WriteLine("{0}\t{1}\t({2})", Count, time, sum);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment