Created
August 21, 2014 19:31
-
-
Save acazsouza/90ceb8d3871535c5a3aa to your computer and use it in GitHub Desktop.
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
namespace ConsoleApplication4 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var lista = new List<string>(); | |
for (int i = 0; i < 700000; i++) | |
{ | |
lista.Add(RandomString(100)); | |
} | |
Stopwatch stopWatch = new Stopwatch(); | |
stopWatch.Start(); | |
var achados = lista.Where(x => x.Contains("A")).Take(10); | |
stopWatch.Stop(); | |
Console.WriteLine(stopWatch.ElapsedMilliseconds); | |
Console.Read(); | |
} | |
private static Random random = new Random((int)DateTime.Now.Ticks);//thanks to McAden | |
private static string RandomString(int size) | |
{ | |
StringBuilder builder = new StringBuilder(); | |
char ch; | |
for (int i = 0; i < size; i++) | |
{ | |
ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65))); | |
builder.Append(ch); | |
} | |
return builder.ToString(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment