-
-
Notifications
You must be signed in to change notification settings - Fork 798
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
Mock.Of<T>()
is much slower than new Mock<T>
(up to several orders of magnitude)
#547
Comments
Mock.Of<T>()
by making SetupProperties
lazyMock.Of<T>()
is much slower than new Mock<T>
(up to several orders of magnitude)
I added a lambda compile cache to Moq and Mock.Of() performance improves. |
Is my understanding right that Mock.Of() equals
If true can we just replace the slow code inside Mock.Of by these faster code lines? |
@informatorius - I'd have to check whether the current implementation is equivalent to what you've shown above, but it seems plausible. Of course this optimisation won't be possible for the parameterized method overload of |
@informatorius - Yes, as far as I can tell by stepping through Moq internals, the code you've shown is what I've run a quick and dirty BenchmarkDotNet test: [Benchmark(Baseline = true)]
public IFoo MockOfT_as_is()
{
return Mock.Of<IFoo>();
}
[Benchmark]
public IFoo MockOfT_simplified()
{
var mock = new Mock<IFoo>();
mock.SetupAllProperties();
return mock.Object;
}
public interface IFoo
{
IFoo AnotherFoo { get; }
string SomeString { get; }
Task<string> GetSomeStringAsync();
} with this result:
So the new implementation might speed up Would you like to submit a PR that replaces the current implementation of If so, please take the following into account:
|
Closing this issue as the performance of There's still the other method overload, |
No description provided.
The text was updated successfully, but these errors were encountered: