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. :-)

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

In reply to Parrot vs. C cagematch (Just for fun) by zentara

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.