[svn:parrot] r40601 - trunk/examples/benchmarks

chromatic at svn.parrot.org chromatic at svn.parrot.org
Sun Aug 16 22:49:47 UTC 2009


Author: chromatic
Date: Sun Aug 16 22:49:46 2009
New Revision: 40601
URL: https://trac.parrot.org/parrot/changeset/40601

Log:
[benchmarks] Removed hard tabs in primes.pasm benchmark.

Removed several Integer PMC creations intended as out parameters for subsequent
ops.  As those ops create their own out PMCs, this allocated twice as many PMCs
as necessary.  The benchmark is now slightly more than twice as fast with no
changes to Parrot itself.

Modified:
   trunk/examples/benchmarks/primes.pasm

Modified: trunk/examples/benchmarks/primes.pasm
==============================================================================
--- trunk/examples/benchmarks/primes.pasm	Sun Aug 16 22:23:13 2009	(r40600)
+++ trunk/examples/benchmarks/primes.pasm	Sun Aug 16 22:49:46 2009	(r40601)
@@ -1,9 +1,9 @@
-# Copyright (C) 2001-2006, Parrot Foundation.
+# Copyright (C) 2001-2009, Parrot Foundation.
 # $Id$
 
 =head1 NAME
 
-examples/benchmarks/primes.pasm - Calculate prime numbers < 50000
+examples/benchmarks/primes.pasm - Calculate prime numbers < 5000
 
 =head1 SYNOPSIS
 
@@ -11,57 +11,62 @@
 
 =head1 DESCRIPTION
 
-Calculates all the prime numbers up to 50000 and prints out the number
+Calculates all the prime numbers up to 5000 and prints out the number
 of primes, the last one found, and the time taken.
 
 =cut
 
-# I1 holds the number we're currently checking for primality
-	new P1, 'Integer'
-	set     P1, 1
-	# I2 holds the highest number we want to check for primality
-	new P2, 'Integer'
-	set     P2, 1000
-	new P6, 'Integer'
-	set	P6, 0
-	print   "N primes up to "
-	print   P2
-	print   " is: "
-	time	N10
-	# I1 counts up to I2
-REDO:   # I3 counts from 2 up to I4 (I1/2)
-        new P3, 'Integer'
-	set     P3, 2
-        new P4, 'Integer'
-	div     P4, P1, 2
-LOOP:   # Check if I3 is a factor of I1
-        new P5, 'Integer'
-	cmod    P5, P1, P3
-	if      P5, OK
-	# We've found a factor, so it can't be a prime and
-	# we can skip right out of this loop and to the next
-	# number
-	branch  NEXT
-OK:     inc     P3
-	le      P3, P4, LOOP
-	# We haven't found a factor so it must be a prime
-	inc	P6
-	set 	P7, P1
-	# print I1
-	# print "\n"	# to get them all
-NEXT:   # Move on to the next number
-	inc     P1
-	le      P1, P2, REDO
-	time	N11
-	print	P6
-	print	"\nlast is: "
-	print   P7
-	print   "\n"
-	sub 	N11, N10
-	print 	"Elapsed time: "
-	print	N11
-	print	"\n"
-	end
+    # P1 holds the number we're currently checking for primality
+    new     P1, 'Integer'
+    set     P1, 1
+
+    # P2 holds the highest number we want to check for primality
+    new     P2, 'Integer'
+    set     P2, 5000
+
+    new     P6, 'Integer'
+    set     P6, 0
+    print   "N primes up to "
+    print   P2
+    print   " is: "
+    time    N10
+
+    # P1 counts up to P2
+    # P3 counts from 2 up to P4 (P1/2)
+    new     P3, 'Integer'
+
+REDO:
+    set     P3, 2
+    div     P4, P1, 2
+    # Check if P3 is a factor of P1
+LOOP:
+    cmod    P5, P1, P3
+    if      P5, OK
+
+    # We've found a factor, so it can't be a prime and
+    # we can skip right out of this loop and to the next number
+    branch  NEXT
+OK:
+    inc     P3
+    le      P3, P4, LOOP
+    # We haven't found a factor so it must be a prime
+    inc     P6
+    set     P7, P1
+    # print I1
+    # print "\n"    # to get them all
+
+    # Move on to the next number
+NEXT:
+    inc     P1
+    le      P1, P2, REDO
+    time    N11
+    say     P6
+    print   "last is: "
+    say     P7
+    sub     N11, N10
+    print   "Elapsed time: "
+    say     N11
+    end
 
 =head1 SEE ALSO
 


More information about the parrot-commits mailing list