开发者

Does using namespaces affect performance or compile time?

If I put all classes of a project in the same n开发者_开发知识库amespace 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?


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.)


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).


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜