From jon.clayden at gmail.com  Wed Aug 12 15:57:10 2009
From: jon.clayden at gmail.com (Jon Clayden)
Date: Wed, 12 Aug 2009 14:57:10 +0100
Subject: [Rd] readBin() arg check has unnecessary overhead (patch
	included)
In-Reply-To: <19074.48183.102932.170100@lynne.math.ethz.ch>
References: <68e086180908110951j2f684448jbb31707b8e02ad0f@mail.gmail.com>
	<19074.48183.102932.170100@lynne.math.ethz.ch>
Message-ID: <68e086180908120657r47104be7l73f7ebb867143a8e@mail.gmail.com>

> ? ?> Dear all,
> ? ?> The version of readBin() in R-devel includes a use of match(), through
> ? ?> `%in%`, which can affect its performance significantly. By using
> ? ?> primitives instead of the rather expensive call to match(), I reduce
> ? ?> the time spent inside readBin() by more than 30% in some of my code
> ? ?> (part of the tractor.base package). A simple patch that does this is
> ? ?> given below. This passes "make check-devel" fine, and I don't see that
> ? ?> it could produce unexpected behaviour -- though I may, of course, be
> ? ?> wrong.
>
> actually, ?%in% ?is liked by programmeRs for its inherent
> robustness combined with "expressiveness" (<-> readability)
> inspite of its potential efficiency loss wrt to ?'=='

Oh, absolutely. I like it and use it widely. But my feeling was that
in core code, a small loss in expressiveness for a significant
performance improvement is a trade worth making.

> and indeed, your patch fails in one case where the original code works:
>
> ?readBin(., NA_character_, ...)
>
> However that case can also be checked explicitly,
> and I will implement the corresponding patch.

Many thanks.

Regards,
Jon



[Rd] readBin() arg check has unnecessary overhead (patch included)
Jon Clayden