The node title suggests what I'm guessing the problem to be in this script. The xs portion of the script seems to output so fast, that newlines printed by Perl can't keep up, and the result is blocks of correct output, separated by blocks of newlines.

This is a script which divides a sequence of numbers by pi, using very high precision, provided by syphilis 's nice port of the Multiple Precision Float Library , which is at Math-MPFR-1.10.

I was making a comparison of speeds between c and Perl, and made 2 identical scripts, 1 c, and 1 Perl. The c script outputs as I expect, i.e 1 number per line. The Perl script outputs correct values, but the output comes in chunks of numbers, followed by chunks of newlines. If you look at the output loop, you can see that I print a newline after each number, but apperently Perl is saving them up and printing them all at once, instead of interleaving them into the output. This is totally bizarre behavior which I have never seen.

Can anyone explain why Perl isn't immediately putting the newline out, before continuing the loop?

#!/usr/bin/perl use warnings; use strict; use Math::MPFR qw(:mpfr); use FileHandle; $|++; use constant MY_PI => 3.1415926535897932384626433832795028841971693993 +751; Rmpfr_set_default_prec(256); print Rmpfr_get_default_prec(),"\n"; my $n = Rmpfr_init2(256); # numerator + my $d = Rmpfr_init2(256); # denominator + my $r = Rmpfr_init2(256); # result + my @barray; Rmpfr_set_d ($d, MY_PI , GMP_RNDD); + my $s3 = Rmpfr_get_str($d,10,0, GMP_RNDD); print "$s3\n"; for (my $i = 0; $i < 1000; $i++){ $barray[$i] = Rmpfr_init2( 256 ); #init array element Rmpfr_set_d ($n, $i , GMP_RNDD); + Rmpfr_div ($barray[$i], $n, $d, GMP_RNDD); } print "check mem, then hit a key\n"; <>; for (my $i = 0; $i < 1000; $i++){ Rmpfr_out_str($barray[$i],10,0,GMP_RNDD); syswrite STDOUT ,"\n"; # print "\n" dosn't work either STDOUT->flush(); } __END__
The bad output looks something like this: a bunch of numbers strung together a bunch of blank lines a bunch of numbers strung together a bunch of blank lines ....... ......

I'm not really a human, but I play one on earth. Cogito ergo sum a bum

In reply to xs outputs faster than perl can keep up 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.