Re: array index and pointer, which is faster?
- From: Xiaohan <wangxiaohan@xxxxxxxxx>
- Date: Fri, 29 Feb 2008 13:21:29 -0800 (PST)
Thank you all guys for your information!
I searched a little bit on the internet and it seems that nowadays the
compiler is really smart that it can do many optimizations. So is it
still worth doing it by ourselfs? Or can we say that we should only
try to optimize the algorithm itself instead the code?
The other example is like this, which is very common in image
processing:
for(i=0; i<h; i++){
for(j=0; j<w; j++){
p[i*w+j] = ...;
}
}
VS.
for(i=0; i<h; i++){
p_temp = p + i*w;
for(j=0; j<w; j++){
p_temp[j] = ...;
}
}
I tested those two cases, and the speed is almost the same...
Any ideas?
Xiaohan
On Feb 29, 3:04 pm, Andrey Tarasevich <andreytarasev...@xxxxxxxxxxx>
wrote:
Doug Miller wrote:
But IWell, take a look at the assembly code you quoted. Don't you see that it
tested it, the speed is almost the same. Can anybody tell me why?
is exactly the same in both cases?
Well, *I* certainly don't see that, and you probably won't either if you look
at it again... :-)
Yeah, I missed the difference somehow... Still I'd stay that in this
case the chances to end up with the same machine code are pretty high
with a modern compiler.
--
Best regards,
Andrey Tarasevich
.
- Follow-Ups:
- Re: array index and pointer, which is faster? - TPA
- From: Default User
- Re: array index and pointer, which is faster? - TPA
- References:
- array index and pointer, which is faster?
- From: Xiaohan
- Re: array index and pointer, which is faster?
- From: Andrey Tarasevich
- Re: array index and pointer, which is faster?
- From: Doug Miller
- Re: array index and pointer, which is faster?
- From: Andrey Tarasevich
- array index and pointer, which is faster?
- Prev by Date: Re: Is there stack associated when a executing an inline function?
- Next by Date: Re: calculating length of an substring - TPA
- Previous by thread: Re: array index and pointer, which is faster?
- Next by thread: Re: array index and pointer, which is faster? - TPA
- Index(es):
Relevant Pages
|