哪个代码运行得更快? [英] which code runs faster?
问题描述
我知道我可以使用unsinged字节,但我需要它用于java,哪些代码在C中运行更快
?
int f1(char b ){
返回(b& 0x80)|(b& 0x7f);
}
或
int f2(char b){
返回b> 0?b:256 + bl
}
?
在我的测试中,f2表现更好。我需要更好的意见。 :-)
谢谢。
I know I can use unsinged byte, but I need it for java, which code runs
faster in C?
int f1(char b) {
return (b&0x80)|(b&0x7f);
}
or
int f2(char b) {
return b>0?b:256+bl
}
?
In my tests f2 performs better. I need a better opinion. :-)
Thanks.
推荐答案
nelu写道:
nelu wrote:
在我的测试中,f2表现更好。我需要更好的意见。 : - )
In my tests f2 performs better. I need a better opinion. :-)
哎呀,我的java测试... f1看起来在C中表现更好。 (gcc -O3)
Ooops, my java tests... f1 performs better in C, it seems. (gcc -O3)
" nelu" < TA ******** @ gmail.com>写道:
"nelu" <ta********@gmail.com> writes:
我知道我可以使用unsinged字节,但我需要它用于java,哪些代码在C中运行得更快?
int f1 (char b){
返回(b& 0x80)|(b& 0x7f);
}
int f2(char b) {
返回b> 0?b:256 + bl
}
I know I can use unsinged byte, but I need it for java, which code runs
faster in C?
int f1(char b) {
return (b&0x80)|(b&0x7f);
}
or
int f2(char b) {
return b>0?b:256+bl
}
返回b& 0xff;
-
...我犯了什么蠢事,我奉献给你。
- 威廉·莎士比亚, _Troilus和Cressida_
return b & 0xff;
--
"...what folly I commit, I dedicate to you."
--William Shakespeare, _Troilus and Cressida_
Ben Pfaff写道:
Ben Pfaff wrote:
return b& 0xff;
return b & 0xff;
对,我写的哪一个应该更快?
Right, still, which of the ones I wrote should be faster?
这篇关于哪个代码运行得更快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!