I know your channel for almost 3 years.... now, I'm revisiting some of your videos, and you, without a pinch of doubt, are one of the most reliable source of knowledge here in RUclips.... you have a very nice way of explaining... not comparing, but its notable that you have, IMHO, a better set of soft-skills than other young and bold content creators.... experience expressed with a great charisma. Thank you.
Thanks for this topic. I always have this question in my thoughts whenever I have to loop through... either to use LINQ or not LINQ. This video makes it clear when to use. I really appreciate your effort and sharing the knowledge.
Enjoyed watching this superb informative but getting knowledge like you on the memory level is tough. Glad I found you learned so much and I hope you are fine and safe !!!
Thank you Andrew! Appreciate the comment. The color theme is something I derived from another (don't remember the name now). The VS version can be found here: gist.github.com/matlus/77a1dd84321f0ef782109b703932d068 I'm afraid I don't know much about Rider.
Maybe it’s a stupid question but I want to know what is the best way of doing this kind of performance testing (stopwatch???) ? Is there a tool which will give me the time it takes for each method to execute?
I have two list object and contains crores of data in both list. I want to loop through with one other list and return a new set of list. Can you please give me the best solution for this to reduce the performance issues?
Thank you, Sir. You quickly became me favorite c# content creator on RUclips since last month when I found you. Unique, insightful videos and very appealing delivery. Thank you again.
LINQ definitely allows you to easily do the wrong thing without realizing it. This is particularly true in "GetUsingMultipleEqualityComparer" - by supplying the comparer you're actually calling Enumrable.Contains(this IEnumerable, value, comparer) rather than HashSet.Contains(value) and it's enumerating the entire set each time. If the test sets were larger, this case would be orders of magnitude slower. That said, a lot of the time, LINQ is not the real problem, the real problem is the data types and/or algorithms that LINQ is being asked to use. To that end, a much better solution is to realize in advance that you want to do case insensitive lookups in your HashSet and supplying an IEqualityComparer that matches your desired lookup. public void GlobalSetup() { // snip _verifiedCustomerNamesInsensitive = new HashSet(_verifiedCustomerNames, StringComparer.OrdinalIgnoreCase); _certifiedCustomerNamesInsensitive = new HashSet(_certifiedCustomerNames, StringComparer.OrdinalIgnoreCase); _aListCustomerNamesInsensitive = new HashSet(_aListCustomerNames, StringComparer.OrdinalIgnoreCase); } [Benchmark] public List GetUsingInsensitiveHashsets() { return _customers .Where(c => _verifiedCustomerNamesInsensitive.Contains(c.FirstName) || _certifiedCustomerNamesInsensitive.Contains(c.FirstName) || _aListCustomerNamesInsensitive.Contains(c.FirstName)).ToList(); } Additionally, if you know you're going to need a "exists in any of these sets" a lot, it does make sense to pre-create that set as well, because you'll save on re-calculating the string hash 3x. That's surprisingly expensive, if it ends up in a hot path. [Benchmark] public List GetUsingPremergedInsensitiveHashset() { return _customers .Where(c => _preMergedNamesInsensitive.Contains(c.FirstName)).ToList(); } LINQ still has some overhead, and if it's truly a hot path you can combine the correct HashSets with a non-LINQ enumeration, but just getting the data right up front already puts you ahead of "GetWithoutLINQForLoop".
Totally agree. One needs to really understand how LINQ works to not fall into traps. That said, some at Microsoft said that design of classes/libraries should make you fall into the "pit of success". I don't believe LINQ meets the bar :)
Shiv, it's been some time you uploaded a video. I hope you are being safe there and doing well.
🙏😊
I know your channel for almost 3 years.... now, I'm revisiting some of your videos, and you, without a pinch of doubt, are one of the most reliable source of knowledge here in RUclips.... you have a very nice way of explaining... not comparing, but its notable that you have, IMHO, a better set of soft-skills than other young and bold content creators.... experience expressed with a great charisma. Thank you.
No video from past 1 month. Hope you are keeping well! 🙏
All is well Yogesh. I've just been busy with work. I'll be starting to post videos soon.
Thanks for this topic. I always have this question in my thoughts whenever I have to loop through... either to use LINQ or not LINQ.
This video makes it clear when to use. I really appreciate your effort and sharing the knowledge.
Thank you Selvakumar! Glad to be of help.
Hello Shiv
Thank you for sharing
Always good to see you with the basic core concepts, which are most important ones
You're welcome Akhil!.
Hi Shiv, I hope you are doing well. It's been a while since you've posted this video. Eagerly looking forward to the new one. 🤞
+1! We miss your videos Shiv!
Just posted one today!
Enjoyed watching this superb informative but getting knowledge like you on the memory level is tough. Glad I found you learned so much and I hope you are fine and safe !!!
You got crazy voice! thanks for video :)
Thank you Kuba! And glad you liked the video too!
Again a best video 🙏
Thank you Saurabh!
Super interesting and fun indeed
Thank you Johnny! Good to see you again too!.
Amazing content as usual. I have to ask - What is that excellent color scheme and font you are using, and are they available for rider ?
Thank you Andrew! Appreciate the comment. The color theme is something I derived from another (don't remember the name now). The VS version can be found here:
gist.github.com/matlus/77a1dd84321f0ef782109b703932d068
I'm afraid I don't know much about Rider.
what model of camera and microphone do you use to record videos?
nice video!
I am sorry if you already mention it somewhere, but what camera and micro are you using for such an amazing quality? That's impressive!
Thanks for the video, Kumar.
What color setup do you use in the Visual Studio? I really like the color combination.
Thank you Mar. I've exported the theme from VS. You can find it here: gist.github.com/matlus/77a1dd84321f0ef782109b703932d068
@@Matlus Awesome! Thank you so much
Maybe it’s a stupid question but I want to know what is the best way of doing this kind of performance testing (stopwatch???) ? Is there a tool which will give me the time it takes for each method to execute?
I have two list object and contains crores of data in both list. I want to loop through with one other list and return a new set of list. Can you please give me the best solution for this to reduce the performance issues?
First ;)
Thank you!
Thank you, Sir. You quickly became me favorite c# content creator on RUclips since last month when I found you. Unique, insightful videos and very appealing delivery. Thank you again.
@@senaszel Thank you! your comment means a lot to me!
LINQ definitely allows you to easily do the wrong thing without realizing it. This is particularly true in "GetUsingMultipleEqualityComparer" - by supplying the comparer you're actually calling Enumrable.Contains(this IEnumerable, value, comparer) rather than HashSet.Contains(value) and it's enumerating the entire set each time. If the test sets were larger, this case would be orders of magnitude slower.
That said, a lot of the time, LINQ is not the real problem, the real problem is the data types and/or algorithms that LINQ is being asked to use. To that end, a much better solution is to realize in advance that you want to do case insensitive lookups in your HashSet and supplying an IEqualityComparer that matches your desired lookup.
public void GlobalSetup()
{
// snip
_verifiedCustomerNamesInsensitive = new HashSet(_verifiedCustomerNames, StringComparer.OrdinalIgnoreCase);
_certifiedCustomerNamesInsensitive = new HashSet(_certifiedCustomerNames, StringComparer.OrdinalIgnoreCase);
_aListCustomerNamesInsensitive = new HashSet(_aListCustomerNames, StringComparer.OrdinalIgnoreCase);
}
[Benchmark]
public List GetUsingInsensitiveHashsets()
{
return
_customers
.Where(c =>
_verifiedCustomerNamesInsensitive.Contains(c.FirstName)
|| _certifiedCustomerNamesInsensitive.Contains(c.FirstName)
|| _aListCustomerNamesInsensitive.Contains(c.FirstName)).ToList();
}
Additionally, if you know you're going to need a "exists in any of these sets" a lot, it does make sense to pre-create that set as well, because you'll save on re-calculating the string hash 3x. That's surprisingly expensive, if it ends up in a hot path.
[Benchmark]
public List GetUsingPremergedInsensitiveHashset()
{
return
_customers
.Where(c =>
_preMergedNamesInsensitive.Contains(c.FirstName)).ToList();
}
LINQ still has some overhead, and if it's truly a hot path you can combine the correct HashSets with a non-LINQ enumeration, but just getting the data right up front already puts you ahead of "GetWithoutLINQForLoop".
Totally agree. One needs to really understand how LINQ works to not fall into traps. That said, some at Microsoft said that design of classes/libraries should make you fall into the "pit of success". I don't believe LINQ meets the bar :)