Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent multiple enumeration in GenericArgsSatisfy #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MaxHayman
Copy link

Doing a property like this I was noticing that the line was being printed twice.

    public uint Number
    {
        get
        {
            Console.WriteLine("Evaluated Number");
            return _testData.Number;
        }
    }

It was being evaluated in the isAllText call and allso in the CheckCriteria call in GenericArgsSatisfy.

Doing a ToList prevents this being evaluated multiple times by preventing multiple enumeration. I plan on having some not as fast logic behind some properties so evaluating these twice would be bad on performance.

This also leads to a ~15% performance increase in my testing.

Before

Method Mean Error StdDev Allocated
Test 946.8 ns 18.60 ns 33.54 ns 1.83 KB

After

Method Mean Error StdDev Allocated
Test 799.0 ns 11.86 ns 11.09 ns 1.68 KB

This also passes all the tests in the test project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant