In the vast majority of cases, barring painstaking optimization, you will probably find that selecting an appropriate algorithm will have a much larger effect on program run time than the language the program is written.

Not particularly tuned; tested on a 6 year old computer:

use warnings; use strict; use Time::HiRes qw/ tv_interval gettimeofday/; my $time0 = [gettimeofday]; use warnings; use strict; my $max = 100; my @primes = ( 2, 3 ); #seed the primes my $this = $primes[-1]; while ( $max > scalar @primes ) { $this += 2; my $sqrt = $this**.5; for (@primes) { if ( $_ > $sqrt ) { push @primes, $this; last; } next if $this % $_; last; } } my $elapsed = tv_interval( $time0, [gettimeofday] ); print "Printing the first $max numbers that are prime... \n"; print "$_ is prime.\n" for @primes; print "Took $elapsed seconds.";
Printing the first 100 numbers that are prime...
2 is prime.
3 is prime.
5 is prime.
...
...
521 is prime.
523 is prime.
541 is prime.
Took 0.00096 seconds.

In reply to Re: performance of perl vs java by thundergnat
in thread performance of perl vs java by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.