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

Bench #64

Merged
merged 14 commits into from
Jul 10, 2020
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
^pkgdown$
^\.github$
^CODE_OF_CONDUCT\.md$
^bench$
118 changes: 118 additions & 0 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
on: push

name: Continuous Benchmarks

jobs:
build:
runs-on: ${{ matrix.config.os }}


name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- {os: ubuntu-latest, r: 'release'}
# fails: https://github.com/luukvdmeer/sfnetworks/pull/64/checks?check_run_id=798178450
# - {os: ubuntu-20.04, r: 'release'}

env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
CRAN: ${{ matrix.config.cran }}

steps:
- uses: actions/checkout@v1

- uses: r-lib/actions/setup-r@master
with:
r-version: ${{ matrix.config.r }}

- uses: r-lib/actions/setup-pandoc@master

- name: Brew and macOS config
if: runner.os == 'macOS'
run: |
brew install pkg-config
brew install udunits
brew install gdal
cat <<EOT >> .Renviron
PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/
PROJ_LIB=/usr/local/opt/proj/share/proj/
# for installing XML package from source
XML_CONFIG=/usr/local/opt/libxml2/bin/xml2-config
EOT
cat <<EOT >> .Rprofile
r <- getOption("repos")
r["CRAN"] <- "https://cran.rstudio.com"
r["rccp_drat"] <- "https://RcppCore.github.io/drat"
config_args <- c("sf" = "--with-proj-lib=/usr/local/lib/", "rgdal" = "--with-proj-lib=/usr/local/lib/ --with-proj-include=/usr/local/include/")
options(configure.args = config_args,
install.packages.compile.from.source = "yes",
repos = r)
EOT

- name: Query dependencies
run: |
install.packages('remotes')
saveRDS(remotes::dev_package_deps(dependencies = TRUE), "depends.Rds", version = 2)
shell: Rscript {0}

- name: Cache R packages
if: runner.os != 'Windows'
uses: actions/cache@v1
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-r-${{ matrix.config.r }}-${{ hashFiles('depends.Rds') }}
restore-keys: ${{ runner.os }}-r-${{ matrix.config.r }}-

- name: Install system dependencies
if: runner.os == 'Linux'
env:
RHUB_PLATFORM: linux-x86_64-ubuntu-gcc
run: |
Rscript -e "remotes::install_github('r-hub/sysreqs')"
sysreqs=$(Rscript -e "cat(sysreqs::sysreq_commands('DESCRIPTION'))")
sudo -s eval "$sysreqs"

# install spatial dependencies
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable
sudo apt update
sudo apt install \
libudunits2-dev \
libgdal-dev \
libgeos-dev \
libproj-dev
git config --global user.email "[email protected]"
git config --global user.name "Robin Lovelace"

- name: Install dependencies
run: |
library(remotes)
deps <- readRDS("depends.Rds")
deps[["installed"]] <- vapply(deps[["package"]], remotes:::local_sha, character(1))
update(deps)
remotes::install_cran("rcmdcheck")
shell: Rscript {0}

- name: Checkout repo
uses: actions/checkout@master

- name: Setup R
uses: r-lib/actions/setup-r@master

- name: Install dependencies
run: |
Rscript -e "install.packages(c('remotes', 'jsonlite'))" -e "remotes::install_deps(dependencies = TRUE)" -e "remotes::install_github('r-lib/bench')"
R CMD INSTALL .
- name: Fetch existing benchmarks
run: Rscript -e 'bench::cb_fetch()'

- name: Run benchmarks
run: Rscript -e 'bench::cb_run()'

- name: Show benchmarks
run: git notes --ref benchmarks show

- name: Push benchmarks
run: Rscript -e "bench::cb_push()"
42 changes: 42 additions & 0 deletions bench/create.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
pkgload::load_all()
# remotes::install_github("luukvdmeer/sfnetworks@develop")
# library(sfnetworks)

bench::mark(check = FALSE,
as_sfnetwork(roxel[1:10, ]),
as_sfnetwork(roxel[1:100, ]),
as_sfnetwork(roxel[1:200, ]),
as_sfnetwork(roxel)
)

# See https://github.com/r-lib/bench/issues/88
# bench::press(n = c(10, 100, 200, nrow(roxel)),
# {
# bench::mark(check = FALSE,
# as_sfnetwork(roxel[1:n, ]),
# )
# }
# )

# # comparison with stplanr (commented out to reduce dependencies)
# library(sfnetworks)
# system.time({
# net = as_sfnetwork(roxel)
# })
# system.time({
# net2 = stplanr::SpatialLinesNetwork(roxel)
# })
# pryr::object_size(net)
# pryr::object_size(net2)
#
# res = bench::press(n = seq(from = 10, to = nrow(roxel), length.out = 5),
# {
# bench::mark(
# check = FALSE,
# time_unit = "ms",
# stplanr::SpatialLinesNetwork(roxel[1:n, ]),
# sfnetworks::as_sfnetwork(roxel[1:n, ])
# )
# }
# )
# ggplot2::autoplot(res)
55 changes: 55 additions & 0 deletions bench/shortpath.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
pkgload::load_all()

library(sf)
library(tidygraph)

net = as_sfnetwork(roxel, directed = FALSE)

bench::mark(
sp_1_9 = {
short_path_1_9 = net %>%
activate("edges") %>%
dplyr::mutate(weight = edge_length()) %>%
tidygraph::convert(to_shortest_path, 1, 9)
})

#
# plot(roxel$geometry)
# plot(sf::st_as_sf(short_path_1_9)$geometry, lwd = 5, add = TRUE)

# sp = function(net, from, to) {
# net %>%
# activate("edges") %>%
# dplyr::mutate(weight = edge_length()) %>%
# tidygraph::convert(to_shortest_path, from, to)
# }
# sp(net, 1, 9)
# bench::press(n = seq(from = 9, to = 99, length.out = 5),
# {
# bench::mark(
# sp(net, 9, n)
# )
# }
# )

# with stplanr # work in progress, not currently working
# library(stplanr)
# sln = SpatialLinesNetwork(roxel)
# p1 = net %>%
# activate(nodes) %>%
# st_as_sf() %>%
# slice(1)
# p9 = net %>%
# activate(nodes) %>%
# st_as_sf() %>%
# slice(1)
#
# stplanr::route_local(sln = sln, from = c(st_coordinates(p1)), to = c(st_coordinates(p9)))
#
# bench::press(n = seq(from = 9, to = 99, length.out = 5),
# {
# bench::mark(
# sp(net, 9, n)
# )
# }
# )