Performance-wise is there any difference on doing this?:
public static Class StaticTestClass()
{
public static void Function(object param) => //Do stuff with "param"
}
and this:
public Class ConstructedTestClass()
{
private object classParam;
public ConstructedTestClass(object param)
{
classParam = param;
}
public void Function() => //Do stuff with "classParam"
}
I think that there wouldn't be any performance differece if done it one single time, but what If I have to do it many times, and call Function()
many times?
Will having many instances of ConstructedTestClass
have a memory impact?
And will calling Function
withing StaticTestClass
with the parameter have any performance impact?
PS: There are similar questions to this but I can't find one that adresses performance upon many calls.
EDIT: I did some tests and this are the results:
With 1000000000
iterations and Creating a ConstructedClass
each iteration.
Static way: 72542ms
Constructed way: 83579ms
In this case the static way is faster, then I tried not creating a class each time Function()
is called, this are the results: [100000000 samples
]
Static way: 7203ms
Constructed way: 7259ms
In this case there's almost no difference so I guess I can do whatever I like the most since i wont be creating 1000000000 instances of the class.