断言在Groovy? [英] Assertions in Groovy?

查看:108
本文介绍了断言在Groovy?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如我所知,断言已被用来断言任何值。但是,如果我添加了大量的断言代码给我的项目,它会影响我的表现吗?

解决方案

是的,断言确实会影响性能。取决于应用程序,它可能也可能不重要。无论如何,断言主要是针对性能开销不重要的情况(测试,脚本)。如果添加自定义消息( assert x> 10,x应该大于10),则开销将变小,因为断言的值不会是记录。

as i know assertions are been used to assert any value. But if i add, large number of assertion code to my project, it that affect my performance?

解决方案

Yes, assertions do affect performance. Depending on the application, it might or might not matter. Anyway, assertions are primarily meant for cases where the performance overhead doesn't matter (tests, scripting). And if you add a custom message (assert x > 10, "x should be greater than 10"), the overhead will be smaller because the assertion's values won't be recorded.

这篇关于断言在Groovy?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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