You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When performing subscript assignment of a std::string to writable::strings there's first a conversion to the r_string class which includes a protection. However, that protection shouldn't be necessary if the result is immediately assigned and there is no translation.
Here's a benchmark compared to Rcpp, where I am generating random strings and assigning them to a pre-allocated vector.
microbenchmark(
rcpp = assign_rcpp(n=1e5, -1), # Assign random strings to Rcpp::CharacterVector
cpp11 = assign_cpp11(n=1e5, -1), # Assign random strings to cpp11::writable::strings
times = 20, setup = gc(full=TRUE))
Unit: milliseconds
expr min lq mean median uq max neval
rcpp 35.09063 36.53801 37.74236 37.3688 39.03084 41.29021 20
cpp11 145.24590 148.24958 154.64878 151.7362 158.87924 177.13784 20
(The performance difference depends a lot on platform, but there's a 4x difference on a mac laptop.)
One possibility is to add some sort of overload or specialization for std::string for subscript assignment and push_back to short circuit the conversion to r_string.
When performing subscript assignment of a
std::string
towritable::strings
there's first a conversion to ther_string
class which includes a protection. However, that protection shouldn't be necessary if the result is immediately assigned and there is no translation.Here's a benchmark compared to Rcpp, where I am generating random strings and assigning them to a pre-allocated vector.
(The performance difference depends a lot on platform, but there's a 4x difference on a mac laptop.)
One possibility is to add some sort of overload or specialization for
std::string
for subscript assignment and push_back to short circuit the conversion tor_string
.Here's an example for
push_back
(https://github.com/traversc/cpp11/blob/main/inst/include/cpp11/strings.hpp#L133)assign_rcpp / assign_cpp11 benchmark functions
push_back benchmark functions
The text was updated successfully, but these errors were encountered: