I was looking at the latest parrot and saw in the examples, a mandelbrot generator, with the equivalent c source code. So I modified them slightly, and ran them thru 1000 generations. Parrot is fast, but it took 5 times the cpu, and roughly 3 times as long on my machine(Duron 800). It would be interesting to compare it to equivalent perl5 code, and if anyone can convert it, please post it. I'm almost there, but the C for statements are a little complicated for me to convert. :-)
I'm not really a human, but I play one on earth. flash japh
Anyways, here is the code for you to try. I slightly modified the original code, to add timer variables.
################################################# # mandel.pasm ...run with "parrot mandel.pasm" time N10 set I0, 0 loop: set S1, " .:,;!/>)|&IH%*#" set I2, 30 YREDO: # C = y*0.1 - 1.5 set N8, I2 set N9, 0.1 mul N7, N8, N9 set N8, 1.5 sub N7, N7, N8 set I1, 0 XREDO: # c = x*0.04 - 2 set N8, I1 set N9, 0.04 mul N6, N8, N9 set N8, 2.0 sub N6, N6, N8 set N3, 0 set N4, 0 set N1, N6 set N2, N7 set I3, 0 KREDO: # t = z*z - Z*Z + r mul N8, N3, N3 mul N9, N4, N4 sub N5, N8, N9 add N5, N5, N1 # Z = 2*z*Z + i add N4, N4, N4 mul N4, N4, N3 add N4, N4, N2 # z = t set N3, N5 # if (z*z + Z*Z > 10) break; mul N8, N3, N3 mul N9, N4, N4 add N8, N8, N9 gt N8, 10.0, PRINT inc I3 lt I3, 112, KREDO PRINT: mod I4, I3, 16 substr S2, S1, I4, 1 print S2 inc I1 lt I1, 75, XREDO print "\n" dec I2 gt I2, 0, YREDO inc I0 lt I0, 1000, loop print I0 print " count in " time N11 sub N11,N10 print N11 print " seconds\n" END: end ############################################
And the c source
/* mandel.c ... compile with gcc -o mandel mandel.c */ #include <stdio.h> #include <time.h> int main() { int x, y, k, counter; char *b = " .:,;!/>)|&IH%*#"; float r, i, z, Z, t, c, C; time_t begin, end; counter = 0; begin = time (NULL); while(counter < 1000){ for (y=30; puts(""), C = y*0.1 - 1.5, y--;) { for (x=0; c = x*0.04 - 2, z=0, Z=0, x++ < 75;) { for (r=c, i=C, k=0; t = z*z - Z*Z + r, Z = 2*z*Z + i, z=t, k<112 +; k++) if (z*z + Z*Z > 10) break; printf ("%c", b[k%16]); } } counter++; } end = time (NULL); printf ("%d count in %ld secs \n", counter, end - begin); }
I'm not really a human, but I play one on earth. flash japh
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Parrot vs. C cagematch (Just for fun)
by tilly (Archbishop) on Apr 07, 2005 at 21:57 UTC | |
by zentara (Archbishop) on Apr 08, 2005 at 11:31 UTC | |
by stvn (Monsignor) on Apr 08, 2005 at 16:47 UTC | |
Re: Parrot vs. C cagematch (Just for fun)
by chromatic (Archbishop) on Apr 08, 2005 at 00:43 UTC | |
Re: Parrot vs. C cagematch (Just for fun)
by Joost (Canon) on Apr 07, 2005 at 21:53 UTC | |
Re: Parrot vs. C cagematch (Just for fun)
by gellyfish (Monsignor) on Apr 08, 2005 at 14:49 UTC | |
Re: Parrot vs. C cagematch (Just for fun)
by tall_man (Parson) on Apr 08, 2005 at 14:17 UTC | |
by etj (Deacon) on Jun 22, 2022 at 19:23 UTC | |
Re: Parrot vs. C cagematch (Just for fun)
by spurperl (Priest) on Apr 10, 2005 at 07:40 UTC | |
by Limbic~Region (Chancellor) on Sep 22, 2005 at 16:38 UTC |
Back to
Meditations