Personally, I know of a few, and wondered what else was out there--perl-related or not. Some of what I'll offer is this:
(1)The unrolling the loop technique (not Friedl's regex optimization). To explain, the first code example is more than likely slower than the second:
for($i = 0; $i <= 10_000; $i++) { $ary[$i] = init_val($i); }
$idx = 0; for($i = 0; $i < 10_000; $i += 10) { $ary[$idx++] = init_val($idx); $ary[$idx++] = init_val($idx); $ary[$idx++] = init_val($idx); ...rest goes here... }
$x = $y * 16; $x = $y << 4; #Much faster
$y * 26 == $y * 16 + $y * 8 + $y * 2 == $y << 4 + $y << 3 + $y << 1;
Update: To the rather bold question of whether I need to optimize: yes. Well, at least in my current project; I'm working on making a game, and parts of the game need to go real fast to make it look realistic. The game will be done in C++, and that's why I focussed the post on 'C-style constructs' and things that may not work too well in an interpreter language. I just posted on this site because (1)there isn't a C site with as good feedback, and (2)some things are general, and many perl programmers came, or have experience in, C or C++. I should have said something to avert this confusion, so I apologize; but I hope that explains myself.
I also fixed the for loop, and added some things that I should have put in the original post.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re (tilly) 1: Optimizations and Efficiency
by tilly (Archbishop) on Jun 30, 2001 at 05:37 UTC | |
by VSarkiss (Monsignor) on Jun 30, 2001 at 07:21 UTC | |
by petdance (Parson) on Jun 30, 2001 at 07:50 UTC | |
by scott (Chaplain) on Jun 30, 2001 at 18:26 UTC | |
by Abigail (Deacon) on Jul 03, 2001 at 03:02 UTC | |
by tilly (Archbishop) on Jul 03, 2001 at 14:29 UTC | |
by Abigail (Deacon) on Jul 04, 2001 at 02:59 UTC | |
by tilly (Archbishop) on Jul 04, 2001 at 05:45 UTC | |
Re: Optimizations and Efficiency
by srawls (Friar) on Jun 30, 2001 at 05:14 UTC | |
by BMaximus (Chaplain) on Jul 01, 2001 at 00:13 UTC | |
Re: Optimizations and Efficiency
by bikeNomad (Priest) on Jun 30, 2001 at 06:45 UTC | |
Re: Optimizations and Efficiency
by Zaxo (Archbishop) on Jun 30, 2001 at 12:24 UTC | |
Re: Optimizations and Efficiency
by bobione (Pilgrim) on Jun 30, 2001 at 14:38 UTC | |
Re: Optimizations and Efficiency
by Beatnik (Parson) on Jun 30, 2001 at 17:23 UTC | |
by toadi (Chaplain) on Jun 30, 2001 at 21:58 UTC |