Comments (1)
Found Rcpp solutions developed from: https://stackoverflow.com/questions/25609174/fast-escaping-deparsing-of-character-vectors-in-r
remotes::install_github("dyfanjones/paws/paws.common", ref="json_escape")
json_escape_unicode <- function(string) {
from <- intToUtf8(1:31, multiple = TRUE)
to <- paste0("\\u00", format(as.hexmode(1:31), width = 2))
for (i in 1:31) {
string <- gsub(from[i], to[i], string, fixed = TRUE)
}
return(string)
}
json_convert_string <- function(string) {
replace <- list(
c("\\", "\\\\"),
c('"', '\\"'),
c("\b", "\\b"),
c("\f", "\\f"),
c("\r", "\\r"),
c("\t", "\\t"),
c("\n", "\\n")
)
for (elem in replace) {
string <- gsub(elem[1], elem[2], string, fixed = TRUE)
}
string <- json_escape_unicode(string)
string <- sprintf('"%s"', string)
return(string)
}
json_convert_string_stringi <- function(string) {
from <- c("\\", '"', "\b", "\f", "\r", "\t", "\n")
to <- c("\\\\", '\\"', "\\b", "\\f", "\\r", "\\t", "\\n")
string <- stringi::stri_replace_all_fixed(string, from, to, vectorize_all =F)
string <- json_escape_unicode_stringi(string)
string <- sprintf('"%s"', string)
return(string)
}
json_escape_unicode_stringi <- function(string) {
from <- intToUtf8(1:31, multiple = T)
to <- paste0("\\u00", format(as.hexmode(1:31), width = 2))
string <- stringi::stri_replace_all_fixed(string, from, to, vectorize_all = F)
return(string)
}
unicode <- c(intToUtf8(1:31, multiple = T), "\\", '"', "\b", "\f", "\r", "\t", "\n")
x <- c(1, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6)
bms <- lapply(x, \(i) {
string <- paste0(sample(c(letters, LETTERS, unicode), i, replace = T), collapse = "")
bm <- bench::mark(
old_paws = json_convert_string(string),
stringi = json_convert_string_stringi(string),
new_paws = paws.common:::json_convert_string(string)
)
bm$id <- i
return(bm)
})
Created on 2024-02-27 with reprex v2.1.0
From this we have significant performance improvement.
from paws.
Related Issues (20)
- paws.common 0.6.2 release HOT 1
- paws.common 0.6.3 release HOT 4
- paginate fails to receive argument inputs when called within a function HOT 4
- Basic list_objects broken with IAM credentials HOT 4
- paws url encoder not encoding protocol HOT 3
- Unable to install paws.common 0.6.3 from CRAN HOT 6
- paws.common 0.6.4 cran release HOT 1
- SNS MessageAttribute are mixed up HOT 8
- How to make a SageMaker endpoint publicly available? HOT 2
- Can't get s3 bucket object when using SSE [minio] [s3 object] [encryption] HOT 7
- paws.common 0.7.0 cran release HOT 1
- Infinite loop while paginating paws.management::cloudwatchlogs()$get_log_events() HOT 12
- Ambient AssumeRoleWithWebIdentity credentials do not work correctly when `AWS_DEFAULT_REGION` is unset HOT 16
- Tidying up auto gen documentation
- unable to retrieve IAM credentials in sagemaker serverless inference HOT 22
- paws 0.5.0 cran release
- Connection to localstack HOT 8
- Two MIME type issues in the Amazon BedrockRuntime client HOT 8
- status of iam_credentials_provider HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from paws.