To LINQ Or Not To LINQ - That is the Question

Поделиться
HTML-код
  • Опубликовано: 4 ноя 2024

Комментарии • 38

  • @VinuP2023
    @VinuP2023 3 года назад +9

    Shiv, it's been some time you uploaded a video. I hope you are being safe there and doing well.
    🙏😊

  • @avecesar
    @avecesar Год назад

    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.

  • @yogij17
    @yogij17 3 года назад +6

    No video from past 1 month. Hope you are keeping well! 🙏

    • @Matlus
      @Matlus  2 года назад +2

      All is well Yogesh. I've just been busy with work. I'll be starting to post videos soon.

  • @mselvam
    @mselvam 3 года назад +4

    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.

    • @Matlus
      @Matlus  3 года назад +2

      Thank you Selvakumar! Glad to be of help.

  • @akhilbandari629
    @akhilbandari629 3 года назад +4

    Hello Shiv
    Thank you for sharing
    Always good to see you with the basic core concepts, which are most important ones

    • @Matlus
      @Matlus  3 года назад +1

      You're welcome Akhil!.

  • @F2H16
    @F2H16 3 года назад +4

    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. 🤞

    • @elarrieux_
      @elarrieux_ 2 года назад

      +1! We miss your videos Shiv!

    • @Matlus
      @Matlus  2 года назад

      Just posted one today!

  • @saurabhchauhan232
    @saurabhchauhan232 3 года назад

    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 !!!

  • @akimbbo_upnext
    @akimbbo_upnext 3 года назад +3

    You got crazy voice! thanks for video :)

    • @Matlus
      @Matlus  3 года назад

      Thank you Kuba! And glad you liked the video too!

  • @saurabhverma4451
    @saurabhverma4451 3 года назад +1

    Again a best video 🙏

    • @Matlus
      @Matlus  3 года назад

      Thank you Saurabh!

  • @MrJonnis13
    @MrJonnis13 3 года назад +1

    Super interesting and fun indeed

    • @Matlus
      @Matlus  3 года назад +1

      Thank you Johnny! Good to see you again too!.

  • @andrewthompson9714
    @andrewthompson9714 3 года назад +2

    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 ?

    • @Matlus
      @Matlus  3 года назад +1

      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.

  • @danielpassos3143
    @danielpassos3143 3 года назад

    what model of camera and microphone do you use to record videos?
    nice video!

  • @hn3m3s1s
    @hn3m3s1s 3 года назад

    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!

  • @Trhnetesiuz
    @Trhnetesiuz 3 года назад

    Thanks for the video, Kumar.
    What color setup do you use in the Visual Studio? I really like the color combination.

    • @Matlus
      @Matlus  3 года назад +1

      Thank you Mar. I've exported the theme from VS. You can find it here: gist.github.com/matlus/77a1dd84321f0ef782109b703932d068

    • @Trhnetesiuz
      @Trhnetesiuz 3 года назад

      @@Matlus Awesome! Thank you so much

  • @sumanahaldar9289
    @sumanahaldar9289 3 года назад

    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?

  • @abdulkapoor4059
    @abdulkapoor4059 3 года назад

    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?

  • @senaszel
    @senaszel 3 года назад +2

    First ;)

    • @Matlus
      @Matlus  3 года назад

      Thank you!

    • @senaszel
      @senaszel 3 года назад +3

      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.

    • @Matlus
      @Matlus  3 года назад

      @@senaszel Thank you! your comment means a lot to me!

  • @pagefault
    @pagefault 3 года назад

    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".

    • @Matlus
      @Matlus  2 года назад

      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 :)