Skip to content

implement frev() - base::rev() that allocates less #5885

Description

@jangorecki
          Since we know now how costly negation is, what about reverting in-place when possible? Reverting with copy costs 1/2  of `rev`. Reverting in-place costs 1/10 of `rev` (no parallelization).
x = rnorm(1e8)
system.time(t1 <- rev(x))
#   user  system elapsed 
#  0.481   0.212   0.693 
system.time(t2 <- reverse(x, copy=TRUE))
#   user  system elapsed 
#  0.117   0.216   0.334 
system.time(t3 <- reverse(x, copy=FALSE))
#   user  system elapsed 
#  0.060   0.000   0.061 
identical(t1, t2)
identical(t1, t3)

x = rnorm(1e8)
n = rep(1e2, 1e8)
system.time(a1 <- frollmax(x, n, align="left", adaptive=TRUE))
#    user  system elapsed 
#  14.330   3.147   7.669
system.time(a2 <- reverse(frollmax(reverse(x, copy=TRUE), reverse(n, copy=TRUE), align="right", adaptive=TRUE), copy=FALSE))
#    user  system elapsed 
#   9.092   0.807   2.687 
identical(a1, a2)

Originally posted by @ben-schwen in #5441 (comment)

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions