Re: Very slow



On 2012-01-12, Ben Morrow <ben@xxxxxxxxxxxx> wrote:

Quoth "George Mpouras" <nospam.gravitalsun@xxxxxxxxxxxxxxxxxx>:
Create a test file with 20000000 same lines of 50 commas (it will be
1020000000 bytes)
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

Now I have a perl and C program running almost the same code. Perl needs
about 6 minutes to finish while the C version finishes at 20 seconds.
The difference is huge. What can I do for a faster perl version
Following the two programs

--== C ==--
<snip>
while (getline(&line, &len, stdin) != -1) {
n = 1;
^^^
0, otherwise you get an off-by-one error

That is your opinion of what the requirement specification should be. This
programd seems to be determining the number of columns in a comma-separated
file (in which commas can be escaped by backslashes).

The initialization n = 1 asserts that the number of columns in an empty
line, or in a line which contains no (unescaped) commas is 1.

If a line contains characters, but no comma, then it clearly has one
column.

Whether an empty line counts as a column is debatable: it's a matter
that is settled in the requirement specification for the program.

Then you can discuss whether there exists an off-by-one bug.
.



Relevant Pages

  • Re: Case sensitive arguments to coco text & copy mechanism
    ... >>Perl seems to be so ubiquitous that this may not be the drawback it used ... I am trying fpx3 now and it does seem very ... It can even handle spaces in arguments to macros. ... > clever way to handle arguments that contain commas with fpx3? ...
    (comp.lang.fortran)
  • Re: need help parsing file for output
    ... I have only the basic - no add-on modules except what comes with Perl ... output all numerics inside double quotes to the number inside the ... column two (top to bottom), ... # 4) ignore lines with only commas ...
    (perl.beginners)
  • Re: need help parsing file for output
    ... Is this possible with Perl 5.x.. ... output all numerics inside double quotes to the number inside the ... column two (top to bottom), ... # 4) ignore lines with only commas ...
    (perl.beginners)
  • Re: Regarding numeric literals
    ... Since a comma is a list separator in Perl, ... all commas with underscores because Perl seems to OK it. ... numeric value, it's a string value. ...
    (comp.lang.perl.misc)
  • Re: question about keeping space with split
    ... perl doesn't do that so you must be doing it yourself. ... Your example doesn't have spaces between the commas. ... non-numeric string in a numerical expression it will be evaluated as 0. ... You can't compare strings with numerical comparison operators. ...
    (comp.lang.perl.misc)