[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] Speedup wc -l
From: |
Pádraig Brady |
Subject: |
Re: [PATCH] Speedup wc -l |
Date: |
Tue, 24 Mar 2015 10:19:25 +0000 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 |
On 24/03/15 07:34, Bernhard Voelker wrote:
> On 03/23/2015 01:03 PM, Pádraig Brady wrote:
>> It just occurred to me that we could simplify from 3 to 2 loops,
>> while also making the code more adaptive to the input,
>> by simply determining the average line length per block.
>
>
> great idea!
>
>> I'll push the attached later.
>
> just 2 minor, almost readability notes:
>
> As you introduced the 'end' variable, why not using it
> in the memchr() case, too?
>
> @@ -290,7 +290,7 @@ wc (int fd, char const *file_x, struct fstatus *fstatus,
> off_t current_pos)
> else
> {
> /* memchr is more efficient with longer lines. */
> - while ((p = memchr (p, '\n', (buf + bytes_read) - p)))
> + while ((p = memchr (p, '\n', end - p)))
Nice one.
> {
> ++p;
> ++lines;
>
> I'd favor multiplication by 15 on the other side, thus avoiding
> to have to check for DIV-By-ZERO manually:
>
> @@ -303,7 +303,7 @@ wc (int fd, char const *file_x, struct fstatus *fstatus,
> off_t current_pos)
> FIXME: This line length was determined in 2015, on both
> x86_64 and ppc64, but it's worth re-evaluating in future with
> newer compilers, CPUs, or memchr() implementations etc. */
> - if (lines == plines || (bytes_read / (lines - plines) > 15))
> + if ((lines - plines) * 15 <= bytes_read)
Better thanks. Actually I'll divide both sides by 15 to
avoid any hint of overflow issues.
thanks!
Pádraig.
- Re: [PATCH] Speedup wc -l, (continued)
- Re: [PATCH] Speedup wc -l, Pádraig Brady, 2015/03/18
- Re: [PATCH] Speedup wc -l, Bernhard Voelker, 2015/03/19
- Re: [PATCH] Speedup wc -l, Pádraig Brady, 2015/03/19
- Re: [PATCH] Speedup wc -l, Bernhard Voelker, 2015/03/19
- Re: [PATCH] Speedup wc -l, Pádraig Brady, 2015/03/19
- Re: [PATCH] Speedup wc -l, Pádraig Brady, 2015/03/23
- Re: [PATCH] Speedup wc -l, Bernhard Voelker, 2015/03/24
- Re: [PATCH] Speedup wc -l,
Pádraig Brady <=
- RE: [PATCH] Speedup wc -l, William Bader, 2015/03/15