Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-25 08:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found