Re: Very slow
- From: Kaz Kylheku <kaz@xxxxxxxxxxx>
- Date: Thu, 12 Jan 2012 22:08:15 +0000 (UTC)
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<snip>
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 ==--
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.
.
- References:
- Very slow
- From: George Mpouras
- Re: Very slow
- From: Ben Morrow
- Very slow
- Prev by Date: Re: Very slow
- Next by Date: Re: Very slow
- Previous by thread: Re: Very slow
- Next by thread: Re: Very slow
- Index(es):
Relevant Pages
|