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

optimise factors_as_string #59

Closed
SymbolixAU opened this issue Nov 11, 2019 · 2 comments
Closed

optimise factors_as_string #59

SymbolixAU opened this issue Nov 11, 2019 · 2 comments

Comments

@SymbolixAU
Copy link
Collaborator

SymbolixAU commented Nov 11, 2019

N <- 2e4
data <- data.frame(
	longitude = runif(N, -180, 180),
	latitude = runif(N, -180, 180),
	tooltip = sample(LETTERS, N, replace = TRUE)
)

microbenchmark::microbenchmark(
  fact = {
    js_str <- jsonify::to_json(data, factors_as_string = FALSE )
  },
  str = {
    js_fac <- jsonify::to_json(data, factors_as_string = TRUE )
  },
  times = 5
)

# Unit: milliseconds
# expr        min         lq       mean     median         uq       max neval
# fact   27.08428   27.31386   28.13172   28.05677   28.92288   29.2808     5
#  str 4653.83055 4678.51414 4688.84328 4683.43302 4692.95960 4735.4791     5

related: SymbolixAU/mapdeck#235

@dcooley
Copy link
Collaborator

dcooley commented Nov 11, 2019

may have a solution

N <- 2e4
data <- data.frame(
  longitude = runif(N, -180, 180),
  latitude = runif(N, -180, 180),
  tooltip = sample(LETTERS, N, replace = TRUE)
  , stringsAsFactors = F
)

js_fac <- jsonify::to_json(data, factors_as_string = TRUE )

microbenchmark::microbenchmark(
  fact = {
    data$tooltip <- as.factor( data$tooltip )
    js_str <- jsonify::to_json(data, factors_as_string = FALSE )
  },
  str = {
    data$tooltip <- as.factor( data$tooltip )
    js_fac <- jsonify::to_json(data, factors_as_string = TRUE )
  },
  times = 5
)
# Unit: milliseconds
# expr      min       lq     mean   median       uq       max neval
# fact 72.17386 77.94805 81.27065 78.44088 82.10928  95.68116     5
#  str 55.44182 81.18584 90.39643 85.23738 88.08029 142.03680     5

@SymbolixAU
Copy link
Collaborator Author

test speed for vectors & lists too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant