Giter Site home page Giter Site logo

Ditch Rcpp about geodist HOT 1 CLOSED

mpadge avatar mpadge commented on June 3, 2024 1
Ditch Rcpp

from geodist.

Comments (1)

mpadge avatar mpadge commented on June 3, 2024 2

And now the timing comparisons:

Compile and load times

Compiling and loading the C version is enormously faster than Rcpp. Total compile-and-load times depend on whether it's done within the same R session or within a new one.

f <- function () {
    pt <- proc.time ()
    devtools::load_all (".", export_all = FALSE, recompile = TRUE)
    print (proc.time () - pt)
}
Version same R session? time (s)
Rcpp no 5.67
Rcpp yes 5.29
C no 0.83
C yes 0.41

So compiling and loading package is around 10 times faster without Rcpp.

Installed package sizes

I used this script to get the sizes of the installed packages:

install.packages("../geodist_0.0.0.9000.tar.gz")
library(fs)
library(tidyverse)
library(rvest)
installed.packages() %>%
    as_data_frame() %>%
    filter (Package == "geodist") %>%
    mutate(pkg_dir =
           sprintf("%s/%s", LibPath,
                   Package)) %>%
    select(Package, pkg_dir) %>%
    mutate(pkg_dir_size = map_dbl(pkg_dir, ~{ fs::dir_info(.x, all=TRUE,
                                                           recursive=TRUE) %>%
                       summarise(tot_dir_size = sum(size)) %>% 
                       pull(tot_dir_size)
               })) %>%
    select (Package, pkg_dir_size)

Results:

Version size (kB)
Rcpp 176.955
C 50.528

So Rcpp inflates the package size to over three times. Finally, the most important comparison

Calculation speed

Based on the following function:

f <- function ()
{
    n <- 1e3
    x <- cbind (-180 + 360 * runif (n), -90 + 180 * runif (n))
    y <- cbind (-180 + 360 * runif (2 * n), -90 + 180 * runif (2 * n))
    colnames (x) <- colnames (y) <- c ("x", "y")
    pt <- proc.time ()
    for (i in 1:10)
    {
        d <- geodist (x, y)
    }
    pt <- proc.time () - pt
    print (pt)
}
Version same R session? time (s)
Rcpp no 6.91
Rcpp yes 3.92
C no 2.61
C yes 2.32

And the C version is definitely faster, but depends very much on whether repeats are conducted within the same R session or not. For a one-off calculation (that is, within a fresh session), the C version is about 3 times faster, reducing to only about 40% faster if repeated within the same session. Either way, Rcpp successfully ditched with some very positive results.

cc @karpfen

from geodist.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.