Created
December 22, 2018 05:45
-
-
Save manofstick/69b489394a172d49f8f6feed3a3ce505 to your computer and use it in GitHub Desktop.
LinqOptimizer's CartLinq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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