简体   繁体   English

在内部大于/小于多少

[英]how greater than/less than works internally

how greater than/less than works internally 在内部大于/小于多少

how much performance hit will be there if i compare 5 with 100 vs 5 with 2,147,483,647 (Integer.MAX_VALUE) 如果我将5与100对比5与2,147,483,647(Integer.MAX_VALUE),将会有多少性能提升

5 < 100 and 5 < Integer.MAX_VALUE

I am asking this question because in some code rank= Integer.MAX_VALUE is returned when data is not present and we will discard data even if rank is greater than 100, so will there be some considerably improvement if i return 101 instead of Integer.MAX_VALUE. 我问这个问题,因为在某些代码中,当不存在数据时将返回rank = Integer.MAX_VALUE,即使rank大于100,我们也会丢弃数据,因此如果我返回101而不是Integer.MAX_VALUE,将会有很大的改善。 I am getting file of millions of records and i have to do this comparison for every record. 我正在获取数百万条记录的文件,并且我必须对每条记录进行此比较。

how much performance hit will be there if i compare 5 with 100 vs 5 with 2,147,483,647 如果我将5与100对比5与2,147,483,647,将会有多少性能冲击

On all 32- and 64-bit hardware architectures that I am familiar with the two comparisons would take exactly the same amount of time. 在我比较熟悉的所有32位和64位硬件体系结构上,这将花费完全相同的时间。

The way to improve performance is by focusing on the number of comparisons that you make (and, more generally, the amount of work your algorithm has to carry out). 改善性能的方法是关注于您进行的比较次数 (更一般地说,算法必须执行的工作量)。

There shouldn't be any difference, so long as the number is small (IE, not 64 bit). 只要数字很小(即,不是64位),就应该没有任何区别。 And the 64 bit would only make a difference if you were comparing 64 bit numbers. 而且,只有在比较64位数字时,64位才会有所作为。 This is typically a single cycle (Or fixed number of small cycles) request in any CPU I am familiar with. 在我熟悉的任何CPU中,这通常是一个周期(或固定数量的小周期)请求。 However, it might be a good idea to throw an exception, or something like that, instead of setting the number to a pre-defined range. 但是,最好抛出一个异常或类似的东西,而不是将数字设置为预定义的范围。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM