TalkingCode
TalkingCode

Reputation: 13557

Does using namespaces affect performance or compile time?

If I put all classes of a project in the same namespace all classes are available everywhere in the project. But if I use different namespaces not all classes are available everywhere. I get a restriction.

Does using namespaces affect the compile time somehow? Since the compiler has less classes in each namespace and not all namespaces are used all the time he may have a little less trouble finding the right classes.

Will using namespaces affect the applications performance?

Upvotes: 13

Views: 3251

Answers (3)

Luis Filipe
Luis Filipe

Reputation: 8708

You should use namespaces according to your logic and ease of human readability and not for performance issues.

Upvotes: 2

Alexander Pacha
Alexander Pacha

Reputation: 9710

I'm quite sure, that putting classes in namespaces does not effect the compile time significantly.

But beware, that you might lose your logical project-structure, if you put every class into the same namespace.

I (and the Resharper) suggest to use namespaces that correspond with the file location (which corresponds with the project structure).

Upvotes: 5

Jon Skeet
Jon Skeet

Reputation: 1500475

It won't affect the execution-time performance.

It may affect the compile-time performance, but I doubt that it would be significant at all, and I wouldn't even like to predict which way it will affect it. (Do you have an issue with long compile times? If so, you may want to try it and then measure the difference... otherwise you really won't know the effect. If you don't have a problem, it doesn't really matter.)

Upvotes: 16

Related Questions