Skip to content
Prev 46151 / 63461 Next

cache most-recent dispatch

Hi Val,

[off list... I don't want to compromise your chances to start a
constructive discussion ;-)]

Thanks for reporting this. Just wanted to mention that the reason I
think the situation is worst when you use the paste() generic defined
in BiocGenerics than when you make paste() a generic with
setGeneric("paste") is because of the signature of the generic.
With the latter dispatch is on the 'sep' and 'collapse' args only
(which is surprising but that's another story), while
with the former it's on ...:

   > setGeneric("paste")
   [1] "paste"

   > paste
   standardGeneric for "paste" defined from package "base"

   function (..., sep = " ", collapse = NULL)
   standardGeneric("paste")
   <environment: 0x157a028>
   Methods may be defined for arguments: sep, collapse
   Use  showMethods("paste")  for currently available ones.

   ## Note that showMethods() is broken (it contradicts the above
   ## that indicates dispatch is on 'sep' and 'collapse').
   > showMethods("paste")
   Function: paste (package base)
   ...="ANY"

   > microbenchmark(fun0(lst), fun1(lst), times=10)
   Unit: milliseconds
         expr       min        lq    median        uq       max neval
    fun0(lst) 27.374228 27.508580 28.144858 28.895889 33.528221    10
    fun1(lst)  5.474173  5.739289  5.803471  6.050482  6.825982    10

   > removeGeneric("paste")
   [1] TRUE

   > setGeneric("paste", signature="...")  # this how it's defined in 
BiocGenerics
   Creating a new generic function for ?paste? in the global environment
   [1] "paste"

   > microbenchmark(fun0(lst), fun1(lst), times=10)
   Unit: milliseconds
         expr        min         lq     median         uq        max neval
    fun0(lst) 149.828201 153.192866 155.845508 157.916067 176.313906    10
    fun1(lst)   4.924387   5.088094   5.114532   5.200432   5.332386    10

Dispatch on ... seems to have a ridiculously high cost!

H.
On 07/01/2013 10:04 PM, Valerie Obenchain wrote: