Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First run of st_apply() is several times slower than second #630

Open
kadyb opened this issue May 11, 2023 · 0 comments
Open

First run of st_apply() is several times slower than second #630

kadyb opened this issue May 11, 2023 · 0 comments

Comments

@kadyb
Copy link
Contributor

kadyb commented May 11, 2023

Have you observed that the first run of st_apply() is several times slower (3-4) than the second and subsequent runs? Generally in R, the first run of functions is usually slower, but the differences are a few percent, but in the case of st_apply() it is very noticeable.

library("stars")

n = 5000
bbox = st_bbox(c(xmin = 0, xmax = 1, ymin = 0, ymax = 1))
r1 = st_as_stars(bbox, nx = n, ny = n, values = rnorm(n^2))
r2 = st_as_stars(bbox, nx = n, ny = n, values = rnorm(n^2))
rr = merge(c(r1, r2))

f = function(x, y) {(x - y) / (x + y)}

system.time(st_apply(rr, 1:2, f))
#> 4.20, 1.26, 1.38

## for comparison
system.time(f(r1, r2))
#> 0.17, 0.17, 0.17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant