Prev: FAQ 8.16 How can I sleep() or alarm() for under a second?
Next: FAQ 5.22 Why can't I just open(FH, ">file.lock")?
From: Xho Jingleheimerschmidt on 9 May 2010 13:15 John Bokma wrote: > Xho Jingleheimerschmidt <xhoster(a)gmail.com> writes: > >> Jürgen Exner wrote: >>> "sopan.shewale(a)gmail.com" <sopan.shewale(a)gmail.com> wrote: >>>> Once you have array, how about? >>>> my $max = (sort { $b <=> $a } @array)[0]; >>> If you insist on being inefficient, >> We are discussing Perl, aren't we? > > Yup, and my experience is that good Perl runs fast enough. Well, that really depends on fast enough for what. On occasion I've had to rewrite certain parts in C to get the required speed, but that is rare. And more to my point, my experience is that using sort is also fast enough, at least in the context where Perl itself is fast enough. I now use List::Util::max or min, but for stylistic reasons, not efficiency reasons. > I suspect > Python to be a bit slower, but note that that's just a suspicion. On top > of that I don't care. Right. Xho
From: Xho Jingleheimerschmidt on 9 May 2010 13:23 J�rgen Exner wrote: > Xho Jingleheimerschmidt <xhoster(a)gmail.com> wrote: >> J�rgen Exner wrote: >>> "sopan.shewale(a)gmail.com" <sopan.shewale(a)gmail.com> wrote: >>>> Once you have array, how about? >>>> my $max = (sort { $b <=> $a } @array)[0]; >>> If you insist on being inefficient, >> We are discussing Perl, aren't we? > > Well, yeah, so? Are you implying that people should use inefficent > algorithms when programming in Perl? Depends on in what domain it is inefficient. > Of course the cost for designing, writing, and maintaining the code is > an important factor, too, and it often justifies the use of a less > efficient algorithm. Right, especially the difference in efficiency is factor of lnN, rather than N or some higher order. > However in this case where there are trivial, short and well-known > algorithms for computing the largest element there is really no excuse > for using a poor algorithm(*). There is no such thing as a trivial algorithm. I've seen people screw up even this one, no matter how short and well-known it may be. Xho
From: John Bokma on 13 May 2010 23:01 Xho Jingleheimerschmidt <xhoster(a)gmail.com> writes: > John Bokma wrote: >> Xho Jingleheimerschmidt <xhoster(a)gmail.com> writes: >> >>> Jürgen Exner wrote: >>>> "sopan.shewale(a)gmail.com" <sopan.shewale(a)gmail.com> wrote: >>>>> Once you have array, how about? >>>>> my $max = (sort { $b <=> $a } @array)[0]; >>>> If you insist on being inefficient, >>> We are discussing Perl, aren't we? >> >> Yup, and my experience is that good Perl runs fast enough. > > Well, that really depends on fast enough for what. For the stuff I do with it, hence "my experience is". ;-). (Mostly processing a lot of data) > On occasion I've > had to rewrite certain parts in C to get the required speed, but that > is rare. And more to my point, my experience is that using sort is > also fast enough, at least in the context where Perl itself is fast > enough. I now use List::Util::max or min, but for stylistic reasons, > not efficiency reasons. Yup, that was more or less my point. >> I suspect >> Python to be a bit slower, but note that that's just a suspicion. On top >> of that I don't care. > > Right. No, really. For (most if not all of) my stuff the speed of Perl/Python is more than enough. Perl is often able to surprise me in a very pleasant wa,y speedwise :-). -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development
From: sln on 16 May 2010 21:37 On Thu, 13 May 2010 22:01:16 -0500, John Bokma <john(a)castleamber.com> wrote: >Xho Jingleheimerschmidt <xhoster(a)gmail.com> writes: > >> John Bokma wrote: >>> Xho Jingleheimerschmidt <xhoster(a)gmail.com> writes: >>> >>>> J�rgen Exner wrote: >>>>> "sopan.shewale(a)gmail.com" <sopan.shewale(a)gmail.com> wrote: >>>>>> Once you have array, how about? >>>>>> my $max = (sort { $b <=> $a } @array)[0]; >>>>> If you insist on being inefficient, >>>> We are discussing Perl, aren't we? >>> >>> Yup, and my experience is that good Perl runs fast enough. >> >> Well, that really depends on fast enough for what. > >For the stuff I do with it, hence "my experience is". ;-). (Mostly >processing a lot of data) Regardless of what the OP literally said, you would recommend sort to find the min or max value? -sln
First
|
Prev
|
Pages: 1 2 3 4 Prev: FAQ 8.16 How can I sleep() or alarm() for under a second? Next: FAQ 5.22 Why can't I just open(FH, ">file.lock")? |