1 # Copyright (C) 2001-2009, Parrot Foundation.
6 examples/benchmarks/primes.pasm - Calculate prime numbers < 5000
10 % time ./parrot examples/benchmarks/primes.pasm
14 Calculates all the prime numbers up to 5000 and prints out the number
15 of primes, the last one found, and the time taken.
19 # P1 holds the number we're currently checking for primality
23 # P2 holds the highest number we want to check for primality
29 print "N primes up to "
35 # P3 counts from 2 up to P4 (P1/2)
41 # Check if P3 is a factor of P1
46 # We've found a factor, so it can't be a prime and
47 # we can skip right out of this loop and to the next number
52 # We haven't found a factor so it must be a prime
56 # print "\n" # to get them all
58 # Move on to the next number
67 print "Elapsed time: "
73 F<examples/benchmarks/primes.c>,
74 F<examples/benchmarks/primes_i.pasm>,
75 F<examples/benchmarks/primes.pl>,
76 F<examples/benchmarks/primes.rb>,
77 F<examples/benchmarks/primes2_p.pasm>,
78 F<examples/benchmarks/primes2.c>,
79 F<examples/benchmarks/primes2.pir>,
80 F<examples/benchmarks/primes2.py>.
88 # vim: expandtab shiftwidth=4 ft=pir: