Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IEnumerable<string> fullList = GetRandomStrings(10000);
- IEnumerable<string> comparisonList = GetRandomStrings(10000);
- var inefficientTime = ProcessList_Inefficient(fullList,comparisonList);
- var efficientTime = ProcessList_Efficient(fullList,comparisonList);
- var msg1 = "Inefficient took "+inefficientTime.ToString() + " milliseconds";
- var msg2 = "Efficient took "+efficientTime.ToString() + " milliseconds";
- msg1.Dump();
- msg2.Dump();
- }
- IEnumerable<string> GetRandomStrings(int count)
- {
- for(int i = 0; i < count;i++){
- yield return Path.GetRandomFileName();
- }
- }
- long ProcessList_Inefficient(IEnumerable<string> firstList, IEnumerable<string> comparisonList){
- Stopwatch sw = Stopwatch.StartNew();
- firstList.ToList().RemoveAll(x=>{
- if(comparisonList.Contains(x)){
- return true;
- }
- return false;
- });
- return sw.ElapsedMilliseconds;
- }
- long ProcessList_Efficient(IEnumerable<string> firstList, IEnumerable<string> comparisonList){
- Stopwatch sw = Stopwatch.StartNew();
- var comparisonListAsList = comparisonList.ToList();
- firstList.ToList().RemoveAll(x=>{
- if(comparisonListAsList.Contains(x)){
- return true;
- }
- return false;
- });
- return sw.ElapsedMilliseconds;
- }
- class Closing{
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement