none
Is Linq to Entities faster in c# than vb.net? RRS feed

  • Question

  • Why the same linq to entities query is faster in c# than in vb.net?:

    from propiedad in typeof(Rectangle).GetProperties()
     join dupla in new Tuple<string, int>[]
                {new Tuple<string, int>("X", 20),
                new Tuple<string, int>("Y", 30),
                new Tuple<string, int>("Width", 150),
                new Tuple<string, int>("Height", 90)} 
     on propiedad.Name equals dupla.Item1
     select new
             {Property = propiedad,
             Value = dupla.Item2}

    from propiedad in GetType(Rectangle).GetProperties() _
     join dupla in New Tuple(Of String, Integer)() _
                    {New Tuple(Of String, Integer)("X", 20), _
                    New Tuple(Of String, Integer)("Y", 30), _
                    New Tuple(Of String, Integer)("Width", 150), _
                    New Tuple(Of String, Integer)("Height", 90)} _
     on propiedad.Name equals dupla.Item1
     select new with _
             {.Property = propiedad, _
             .Value = dupla.Item2}

    the first query, consumes around 0.009 secs in comparison the second query cosumes around 0.0012 secs.

    Besides if you assigns both queries to a variable, let's say "properties" the generated type of this variable is different between them:

    the first query: 

    Name         

    properties  

    Value                        

     {System.Linq.Enumerable.JoinIterator<System.Reflection.PropertyInfo,System.Tuple<string,int>,string,<>...}    

    Type

    System.Collections.Generic.IEnumerable<<>f__AnonymousType0<System.Reflection.PropertyInfo,int>> {System.Linq.Enumerable.JoinIterator<System.Reflection.PropertyInfo,System.Tuple<string,int>,string,<>f__AnonymousType0<System.Reflection.PropertyInfo,int>>}

    the second query: 

    Name         Value                        type  

    properties    query in memory      <enumerable type>

    Theses variations fairly affect, because you'll get different results when processing "properties" variable; and that's no good to code with confidence.

    thanks in advance for yours comments respecting this stuff.


    • Edited by Jesus_M1 Wednesday, March 1, 2017 12:31 AM
    Wednesday, March 1, 2017 12:26 AM

All replies

  • Hi Jesus_M1,

    >>Is Linq to Entities faster in c# than vb.net?

    As far as I know, whatever vb.net or c# will be compiled as IL language. So I don't think that Linq to Entities faster in c# than vb.net.

    Best regards,

    Cole Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, March 1, 2017 9:36 AM
    Moderator
  • C# is not inherently faster. Both languages generate to IL and run on the CLR. For most features they even generate the same IL. I do not think there should be a performance difference with a LINQ to Entities query in C# or VB.NET.


    william xifaras

    Friday, March 10, 2017 8:06 PM