Re: array index and pointer, which is faster?
- From: lawrence.jones@xxxxxxxxxxx
- Date: Fri, 29 Feb 2008 14:38:47 -0500
Xiaohan <wangxiaohan@xxxxxxxxx> wrote:
It seems that Case 1 needs multiplication/shifting to calculate the
address/index and the second case needs only an ADD operation. But I
tested it, the speed is almost the same. Can anybody tell me why?
Because on most current processors multiplication is fast and shifting
is extremely fast, and there are multiple ALUs to allow address
arithmetic to be done in parallel with other operations so it takes no
additional time. This has very little to do with C, though.
-Larry Jones
I always send Grandma a thank-you note right away. ...Ever since she
sent me that empty box with the sarcastic note saying she was just
checking to see if the Postal Service was still working. -- Calvin
.
- References:
- array index and pointer, which is faster?
- From: Xiaohan
- array index and pointer, which is faster?
- Prev by Date: Re: array index and pointer, which is faster?
- Next by Date: Re: array index and pointer, which is faster?
- Previous by thread: Re: array index and pointer, which is faster?
- Next by thread: calculating length of an substring
- Index(es):