Reputation: 127
I have two questions about making code faster, and exactly how much certain things will slow down my program.
First off, method parameters. Lets say I have a program which has a base class called Account, and then I create many instances of this class Account. In the class, it has a method called Example, with heaps of method parameters. Is it slow to do this? Is hard coding the stuff faster, if so how much? Example:
public class Example
{
public void DoSomething(string One, string Two, string Three, string Four, string Five, string Six, string Seven, string Eight, string Nine, string Ten, string Eleven)
{
// make a WebRequest using these parameters.
}
}
Secondly, is it bad to have a class with only one member inside of it, a instance of a base class, like Example (above). For example:
static class ExampleOne
{
public static Example example = new Example();
}
And then using it like this:
static void Main(string[] args)
{
ExampleOne.example.DoSomething(parameters);
}
Thanks for your help!
Upvotes: 0
Views: 198
Reputation: 540
Concerning your second question:
It depends on what you want to accomplish, but I think you should either use a static method or implement the Singleton design pattern instead.
Upvotes: 0
Reputation: 941635
// make a WebRequest using these parameters.
You are doing this fundamentally wrong. Network latency ensures that this method is going to take many milliseconds to execute. Anything you could gain from tinkering with the way you call this method, at best measured at a handful of nanoseconds, is never going to be observable.
Your started wrong, you didn't use a profiler to find what needed to be optimized.
Upvotes: 4