Leopold Toetsch wrote:
No I hadn't, but I just did, using those exact commands(no additional options to Configure.pl), and had no perceivable performance change using any of the parrot variances(default, -P, -j). Is there a way to verify that an optimized build was truly made? Did you expect to see much of any difference? GCC issues(running 3.2.3)?Did you have an optimized parrot compile?( make progclean ; perl Configure.pl ... --optimize ; make -s)
Alright...all versions are attached (sorry for spamming the list, but others might be interested). Some of the code is ugly (done around 3:00 in the morning), and some are in languages I am less then fluent in (last touched any flavor of assembly in 1985, and barely touched it then), so be kind. I don't believe I'm being too unfair to any of the languages, though feel free to tell me otherwise.-Tupshin Code available if anybody cares.Yes please.
The python and c versions of prime2 come from a tutorial on optimizing python by writing extensions in C
http://kortis.to/radix/python_ext/
Modified slighly to behave more analogously to the first test, and some compilation bugs fixed.
TIA, leo
WATF (welcome after the fact) -Tupshin
#include <stdio.h>
int main()
{
int I1 = 1;
int I2 = 100000;
int I3;
int I4;
int I5;
printf("\nThe primes up to ");
printf("%d", I2);
printf(" are:\n");
REDO:
I3 = 2;
I4 = I1 / 2;
LOOP:
I5 = I1 % I3;
if (I5) {goto OK;}
goto NEXT;
OK:
I3++;
if (I3 <= I4) {goto LOOP;}
printf ("%d", I1);
printf ("\n");
NEXT:
I1++;
if (I1 <= I2) {goto REDO;}
}
primes.pl
Description: Perl program
# Some simple code to print out the primes up to 100
# Leon Brocard <[EMAIL PROTECTED]>
# I1 holds the number we're currently checking for primality
set I1, 1
# I2 holds the highest number we want to check for primality
set I2, 100000
print "The primes up to "
print I2
print " are:\n"
# I1 counts up to I2
REDO: # I3 counts from 2 up to I4 (I1/2)
set I3, 2
div I4, I1, 2
LOOP: # Check if I3 is a factor of I1
mod I5, I1, I3
if I5, 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 I3
le I3, I4, LOOP
# We haven't found a factor so it must be a prime
print I1
print "\n"
NEXT: # Move on to the next number
inc I1
le I1, I2, REDO
end
int main(){
int i=0, l=0, max=10000;
while (1) {
if (isprime1(i)==1) {
printf("%i\n",i);
l++;
}
i++;
if (i==max){
break;
}
}
printf("primes calculated to %i\n",max);
}
int isprime1(int input)
{
int n;
if (input < 1) {
return 0;
}
n = input - 1;
while (n > 1){
if (input%n == 0) return 0;
n--;
}
return 1;
}
import os,sys
def isprime1(input):
if input < 1:
return 0
n = input-1
while n > 1:
if input%n == 0:
return 0
n = n - 1
return 1
def main():
i = 0
l = 0
max = 10000
while 1:
if isprime1(i):
l = l +1
print i
i = i + 1
if i == max:
break
print "primes calculated to ",max
if __name__ == "__main__":
main()
set I1, 0 set I2, 0 set I3, 0 set I4, 10000 BEGINLOOP: branch PRIMECHECK ISPRIME: print I1 print "\n" inc I2 NOTPRIME: inc I1 eq I1,I4, DONE PRIMECHECK: set I5, I1 lt I5,1,NOTPRIME set I6,I5 dec I6 NLOOP: mod I7, I5, I6 eq I7, 0, NOTPRIME dec I6 gt I6, 1, NLOOP branch ISPRIME DONE: print"primes calculated to " print I1 print "\n" end
