Skip to content

A code sample of using two different ways to deal with lists, the most conventional way and the yield approach, all measured with benchmark

Notifications You must be signed in to change notification settings

GusBedasi/YieldReturn2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Using Yield return

This is another example of using Yield return instead of convetionally return lists.

Benefits

When you use yield return you can work each piece of data as you need it, theres no need to create the whole list on the memory, improving the application resource management and the time, GC, etc has a greater improving as you can see on the image below:

Benchmark result:

img

Observation

When you use yield return you necessarily need to return a IEnumeral<something> so the compiler can generate for you the Enumerable and Enumerator implementation to deal with each return of element, follows a gist of the code genereated by the compiler.

compiler generated code example

About

A code sample of using two different ways to deal with lists, the most conventional way and the yield approach, all measured with benchmark

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages