Iam playing with lambda, linq and parallel and one question arrives.
Is lambda faster than linq queries?
O write some test code (Fork it in GitHub) and the lambda method seems faster. It is true or i am missing something?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Your queries aren’t the same.
Query expression:
Regular extension method calls:
The first one calls
Whereonce; the second callsWherethree times. To make them behave exactly the same you should use:At that point, the two forms will compile to exactly the same code.
Additionally, there’s a huge hole in your testing: you’re testing building the query… you’re never actually evaluating it:
You must use the query in some form, e.g. calling
Count()on it, in order to make it actually “execute”. (You’ll need to change the type to the genericIEnumerableform, e.g. usingvar.) The time taken to simply construct the query is basically irrelevant in almost all cases.