--0-1157793495-1119383752	6009
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit

Just new to Ruby since last week, running  my same functional program on the windows XP(Pentium M1.5G), the Ruby version is 10 times slower than the Java version. The program is to find the prime numbers like 2, 3,5, 7, 11, 13...  Are there setup issues? or it is normal? 
1. Ruby result:  101 seconds
2. Java result:9.8 seconds
3. Perl result:62 seconds

 
Ruby: 
 
def is_prime(number)
 for i in 2..(number-1)
 if number%i then return false
 end
        end
 return true
end
######### star here:How many primes in 2 to  50000? 
max_numberP000
start_number totaltimeme.now.to_i
for i in start_number..max_number
if is_prime(i) 
#puts i
total+end
end
timeme.now.to_i-time
puts "There are #{total} primes between #{start_number} and #{max_number}"
puts "Time taken #{time} seconds"

 
Java :
import java.io.*;
class prime 
{
   private static boolean isPrime(long i)
   {
       for(long test  ; test < i; test++)
       {
     if((i%test) 0)
     {
    return false;
     }
       }       
       return true;
   }
   public static void main(String[] args) throws IOException 
   {
       long start_time  ystem.currentTimeMillis();
       long n_loops  50000;
       long n_primes  ;
       for(long i  ; i < _loops; i++)
       {
     if(isPrime(i))
           {
         n_primes++;
           }
       }
   
       long end_time  ystem.currentTimeMillis();
       System.out.println(n_primes + " primes found");       
       System.out.println("Time taken   + (end_time - start_time)+ "millseconds");
   }
}
 
 
Perl: 

######### star here:How many primes in 2 to 50000? 

# start timer

$start  ime();

$max_numberP000;

$start_number 

$total

for ($iitart_number;$ii<ax_number;$ii++){ 

if (&is_prime($ii)) 

{$total+

}

# end timer

$end  ime();

# report

print "There are ",$total," primes between ",$start_number," and ",$max_number,"\n";

print "Time taken was ", ($end - $start), " seconds"; 

sub is_prime() {

my ($number)  _[0]; 

my ($si)  

for ($si;$si<$number;$si++){

if ($number % $si 0) {

return 0;}

}

return 1 

}

 

		
---------------------------------
Discover Yahoo!
 Find restaurants, movies, travel & more fun for the weekend. Check it out!
--0-1157793495-1119383752	6009--