Created
January 31, 2014 07:33
-
-
Save lacolaco/8727929 to your computer and use it in GitHub Desktop.
Range v.s. Repeat with SelectMany
This file contains hidden or 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
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; } | |
} |
This file contains hidden or 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
==== Pattern Range ==== | |
27139 | |
==== Pattern Repeat ==== | |
5849 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment