Skip to content

Instantly share code, notes, and snippets.

@lacolaco
Created January 31, 2014 07:33
Show Gist options
  • Save lacolaco/8727929 to your computer and use it in GitHub Desktop.
Save lacolaco/8727929 to your computer and use it in GitHub Desktop.
Range v.s. Repeat with SelectMany
class Program
{
static void Main(string[] args)
{
var initial = new Item[] {
new Item() { value = "Hoge", count = 10000 },
new Item() { value = "Fuga", count = 10000 },
new Item() { value = "Piyo", count = 10000 },
};
var sw = new Stopwatch();
"==== Pattern Range ====".Print();
sw.Restart();
var patternRange = initial.SelectMany(x => Enumerable.Range(0, x.count).Select(_ => x)).ToList();
sw.ElapsedTicks.Print();
"==== Pattern Repeat ====".Print();
sw.Restart();
var patternRepeat = initial.SelectMany(x => Enumerable.Repeat(x, x.count)).ToList();
sw.ElapsedTicks.Print();
Console.ReadLine();
}
}
class Item
{
public string value { get; set; }
public int count { get; set; }
}
==== Pattern Range ====
27139
==== Pattern Repeat ====
5849
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment