joelverhagen / NCsvPerf

A test bench for various .NET CSV parsing libraries
https://www.joelverhagen.com/blog/2020/12/fastest-net-csv-parsers
MIT License
71 stars 14 forks source link

ICsvReader returns IEnumerable instead of List #46

Open leandromoh opened 2 years ago

leandromoh commented 2 years ago

Usually we should program to interfaces, not implementations, to abstract implementation details and focus on behaviour. I think it is more fair does not obligate implementations to return a specific type (eg. List) @joelverhagen

If some implementation can work better with IEnumerable instead of List, I dont see any reason to force it get worse.

Obligate implementations to use list hurt performances unnecessarily because as the size of the list gets larger, it has the cost of creating a new buffer internally and copy over all of the existing elements.

So this PR makes 2 adjusts:

  1. adjusts to ICsvReader returns IEnumerable instead of List
  2. adjusts some implementations to use yield return instead of mandatorily return a List

I can revert point 2 if wanted.