On Fri, 12 Apr 2002, Jonathan E. Paton wrote: > > I'm a litttle puzzled as to why max2 (foreach with if modifier) is > > consistently about 25% faster than max4 (foreach with ternary operator). > > My guess is that the difference is due to how often the assignment is > > done. With the if modifier, the assignment is done only when necessary; > > with the ternary operator, the assignment is done for every element of > > the array (most of the time uselessly assigning $max = $max). > > > > Useless assignment in Perl is costly, like any language. Perl also has to > do reference counting that means it takes a few extra cycles. A more fair > experiment is to benchmark if/else vs. ternary operator where each condition > does the same thing... they should match, otherwise somebody hasn't optimised > it correctly.
Speaking of optimisation: Shouldn't this useless assignment be optimised away? I can't think of a situation where assigning a variable to itself would do anything but consume CPU time, so it seems from my (unqualified?) point of view that this would be a good target for otpimisation... Elias -- "There are people who don't like capitalism, and there are people who don't like PCs, but there's no one who likes the PC who doesn't like Microsoft." -- Bill Gates -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]