performance of basic set theory (intersection, union, exclusion) over large sets of objects, which is faster linq in c# or f#? [closed]

StackOverflow https://stackoverflow.com/questions/14544117

  •  05-03-2022
  •  | 
  •  

문제

I want to compare two collections of entity framework pocos based on union and intersection. I'm trying to find out if out of the box it would be better to process these sets using f# instead of linq?

도움이 되었습니까?

해결책

You don't need to run a profiler -- F# 3.0 supports LINQ, so you should be able to put together a small benchmarking project which uses both LINQ and the standard F# Set<'T> and measures the time to complete whatever operations you need (use System.Diagnostics.Stopwatch for this).

Here's the thing -- the answer to this question is highly dependent on your exact needs, so you need to do a bit of testing to see which is faster for your use case. For example, if you create a little benchmark app and find that LINQ (in C# or F# 3.0) is faster by 10ms, do you just go with LINQ because it's faster? Maybe, or maybe not -- it depends on whether that 10ms savings is important for your application; in most cases, it probably isn't, so you should go with whatever solution is easiest to integrate with the rest of your code.

Personally, I'd go with F# 3.0 and LINQ here, because it allows for a very succinct definition, and it may also be faster if EF can offload some or all of the computation to the database server.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top