Skip to content

Benchmarking replacing C++ by R code #49

@AlbanSagouis

Description

@AlbanSagouis

Goal

In an effort to make parzer easier to maintain, all C++ code was translated to base R code and stringi functions.

Methods

Compared versions are aacd37 for the C++ version and 6be82b5 for the R version.

Results

C++ functions seem to be constantly faster than R versions. To a point that the weight of maintaining a C++ package seems justified.

R> microbenchmark::microbenchmark(
        R = parzeR::parse_lat("32 4 46"),
        cpp = parzer::parse_lat("32 4 46")
      )
Unit: microseconds
 expr   min    lq  mean median    uq    max neval
    R 86.22 87.37 90.44  88.38 90.30 212.05   100
  cpp 21.69 22.55 24.59  23.62 24.15  93.28   100
R> 
R> microbenchmark::microbenchmark(
        R = parzeR::parse_lon("32 4 46"),
        cpp = parzer::parse_lon("32 4 46")
      )
Unit: microseconds
 expr   min    lq  mean median    uq   max neval
    R 90.45 91.68 94.42  92.64 93.95 201.1   100
  cpp 24.19 24.89 26.96  25.87 26.40 107.8   100
R> 
R> microbenchmark::microbenchmark(
        R = parzeR::parse_latlon("32 4 46N, 37 02 34.5E"),
        cpp = parzer::parse_llstr("32 4 46N, 37 02 34.5E")
      )
Unit: microseconds
 expr   min    lq  mean median    uq   max neval
    R 250.5 257.8 272.6  263.9 273.5 488.5   100
  cpp 197.3 207.3 221.9  213.2 222.2 349.9   100
R> microbenchmark::microbenchmark(
        times = 15,
        R = parzeR::parse_latlon(rep("32 4 46N, 37 02 34.5E", 10^4)),
        cpp = parzer::parse_llstr(rep("32 4 46N, 37 02 34.5E", 10^4))
      )
Unit: milliseconds
 expr    min     lq mean median   uq    max neval
    R 1908.3 1911.5 1926 1915.2 1923 1978.7    15
  cpp  405.4  406.4  409  407.7  410  418.4    15
R> 
R> microbenchmark::microbenchmark(
        times = 15,
        R = parzeR::parse_lon_lat(rep("32 4 46N", 10^4), rep("37 02 34.5E", 10^4)),
        cpp = parzer::parse_lon_lat(rep("32 4 46N", 10^4), rep("37 02 34.5E", 10^4))
      )
Unit: milliseconds
 expr   min    lq  mean median    uq   max neval
    R 574.7 578.6 583.1  582.6 587.3 594.3    15
  cpp 200.4 201.7 209.5  203.8 208.2 270.4    15
There were 50 or more warnings (use warnings() to see the first 50)
R> 
R> microbenchmark::microbenchmark(
        times = 15,
        R = parzeR::parse_hemisphere(rep("32 4 46N", 10^4), rep("37 02 34.5E", 10^4)),
        cpp = parzer::parse_hemisphere(rep("32 4 46N", 10^4), rep("37 02 34.5E", 10^4))
      )
Unit: milliseconds
 expr   min    lq  mean median    uq   max neval
    R 580.6 587.9 594.0  590.2 592.3 650.4    15
  cpp 199.6 200.0 205.5  200.9 203.2 261.6    15
There were 50 or more warnings (use warnings() to see the first 50)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions