[Rd] str() with attr(*, "names") is extremely slow for long vectors

Martin Maechler maechler at stat.math.ethz.ch
Mon May 8 10:28:01 CEST 2006


>>>>> "HenrikB" == Henrik Bengtsson (max 7Mb) <hb at stat.berkeley.edu>
>>>>>     on Fri, 5 May 2006 11:58:19 -0700 writes:

    HenrikB> Hi,
    HenrikB> I noticed some time ago that, for instance, named vectors that are
    HenrikB> really makes str() really slow when displaying the names attribute.

    HenrikB> I don't know exactly when this started, but it
    HenrikB> wasn't the case say 1-2 years ago.  Example (on a WinXP 1.8GHz):

Thank you, Henrik, for the note.
Indeed, str() is unnecessary slow for long character vectors in
general, not just when they are names(); and Rprof() +
Rprofsummary() quickly reveal were the culprits lie.

This shouldn't be too hard to improve, I'm having a look.

Martin Maechler, ETH Zurich



    >> s <- 1:1000; names(s) <- s
    >> system.time(str(s))
    HenrikB> Named int [1:1000] 1 2 3 4 5 6 7 8 9 10 ...
    HenrikB> - attr(*, "names")= chr [1:1000] "1" "2" "3" "4" ...
    HenrikB> [1] 0.08 0.00 0.09   NA   NA

    >> s <- 1:100000; names(s) <- s
    >> system.time(str(s))
    HenrikB> Named int [1:100000] 1 2 3 4 5 6 7 8 9 10 ...
    HenrikB> - attr(*, "names")= chr [1:100000] "1" "2" "3" "4" ...
    HenrikB> [1] 8.82 0.00 9.11   NA   NA

    HenrikB> I looks like all strings elements are processed although only the
    HenrikB> first few are displayed.

    HenrikB> Cheers

    HenrikB> Henrik

    HenrikB> ______________________________________________
    HenrikB> R-devel at r-project.org mailing list
    HenrikB> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>>> "HenrikB" == Henrik Bengtsson (max 7Mb) <hb at stat.berkeley.edu>
>>>>>     on Fri, 5 May 2006 11:58:19 -0700 writes:

    HenrikB> Hi, I noticed some time ago that, for instance,
    HenrikB> named vectors that are really makes str() really
    HenrikB> slow when displaying the names attribute.  I don't
    HenrikB> know exactly when this started, but it wasn't the
    HenrikB> case say 1-2 years ago.  Example (on a WinXP
    HenrikB> 1.8GHz):

    >> s <- 1:1000; names(s) <- s system.time(str(s))
    HenrikB>  Named int [1:1000] 1 2 3 4 5 6 7 8 9 10 ...  -
    HenrikB> attr(*, "names")= chr [1:1000] "1" "2" "3" "4" ...
    HenrikB> [1] 0.08 0.00 0.09 NA NA

    >> s <- 1:100000; names(s) <- s system.time(str(s))
    HenrikB>  Named int [1:100000] 1 2 3 4 5 6 7 8 9 10 ...  -
    HenrikB> attr(*, "names")= chr [1:100000] "1" "2" "3" "4"
    HenrikB> ...  [1] 8.82 0.00 9.11 NA NA

    HenrikB> I looks like all strings elements are processed
    HenrikB> although only the first few are displayed.

    HenrikB> Cheers

    HenrikB> Henrik

    HenrikB> ______________________________________________
    HenrikB> R-devel at r-project.org mailing list
    HenrikB> https://stat.ethz.ch/mailman/listinfo/r-devel



More information about the R-devel mailing list