空指针测试性能 [英] Null pointer test performance

查看:143
本文介绍了空指针测试性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

测试C#中的引用类型变量是否为空指针(如 if(x == null) ...的性能是什么? )相比,测试一个小于零的整数,或者甚至一个bool为false?

What is the performance of testing whether a reference-type variable in C# is a null-pointer (like if (x == null) ...) compared to testing for an integer being smaller than zero or even a bool being false?

还有其他问题知道这样的空指针测试,例如

Are there other issues know regarding such null-pointer tests, e.g. is garbadge produced?

我对游戏的每一帧进行了上百次这些测试,我想知道这些是否会导致问题,

I do hundred of these tests for every frame of a game and I was wondering if these could cause problems or could be implemented more efficiently?

推荐答案

无效测试可能相当于简单的等于0测试。他们是非常,非常便宜 - 每帧只有几百个是完全不重要,除非你有一个帧速率在百万:)

Nullity tests are likely to be equivalent to simple "equal to 0" tests. They're very, very cheap - mere hundreds per frame should be completely insignificant unless you've got a frame rate in the millions :)

您应该对自己的应用进行配置,以了解时间是在哪里实际花费的时间 - 这比只是猜测更有效率。理想情况下,您还应该尝试编写一些基准测试,以便您不仅可以衡量当前性能,还可以注意是否由于任何特殊更改而导致性能变差。

You should profile your app to find out where the time is actually being spent - it's a lot more productive than just guessing. Ideally, you should also try to write some benchmarks so that you can not only measure current performance, but also notice if it gets significantly worse due to any particular change.

这篇关于空指针测试性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆