For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > October 2006 > Re: Optimisation of loops









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Optimisation of loops
oroszib@vpg.sulinet.hu

2006-10-13, 7:56 am

Robin Sheat wrote:
> yeah, I understand Perl references, but you can't (afaik) do C-style pointer
> arithmetic with them.


Luckily!

> Without pointer arithmetic, this access:
> $details->[ $j ]
> is something akin to (in C/Perl/psuedocode mishmash):
> address_of($details) + sizeof(void *) * $j
> That multiply is happening 100 million times.


Apart from Perl:

As a side note, I strongly discourage you to use this kind of
"optimization" in C with pointer arithmetic, as not only it doesn't make
the code faster, but it also makes the code less readable, and limits
the optimizer to do truly advanced optimizations, which gives MUCH MORE
savings, than what you could ever gain by supposedly "saving" a
multiplication at array indexing.

Read here for some beginning ideas about why:
http://en.wikipedia.org/wiki/Loop_transformation

Believe me, today's compilers are really smart when it comes to
optimizing age-old problems (which array indexing in loops is).

--
Greets,
Balázs

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com