首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >RJSONIO与rjson -更好的调优

RJSONIO与rjson -更好的调优
EN

Stack Overflow用户
提问于 2013-03-09 15:38:05
回答 2查看 3.1K关注 0票数 17

更新:

tl;drRJSONIO不再是两个选项中较快的一个。相反,rjson现在的速度要快得多。

有关结果的其他确认,请参阅备注

我的印象是RJSONIO应该比rjson更快。

然而,我得到了相反的结果。

我的问题是:

  • 是否可以/应该执行任何调整来改善RJSONIO的结果?(例如,我是不是忽略了什么?)

下面是使用真实数据(其中U是json网页的内容)和模拟的json进行的比较

## REAL DATA
library(microbenchmark)
> microbenchmark(RJSONIO::fromJSON(U), rjson::fromJSON(U))

Unit: milliseconds
                  expr       min        lq    median        uq      max
1   rjson::fromJSON(U)  29.46913  30.16218  31.74999  34.11012 158.6932
2 RJSONIO::fromJSON(U) 175.11514 181.67742 186.52871 195.90646 414.6160

> microbenchmark(RJSONIO::fromJSON(U, simplify=FALSE), rjson::fromJSON(U))
Unit: milliseconds
                                    expr       min       lq    median        uq        max
1                     rjson::fromJSON(U)  27.92341  28.7430  29.60091  30.63291 1 143.9478
2 RJSONIO::fromJSON(U, simplify = FALSE) 173.30136 179.5815 183.94315 190.17245 2 328.8996

模拟数据示例

(类似的结果)

# MOCK DATA
U <- toJSON(list(1:10, LETTERS, letters, rnorm(20)))

microbenchmark(RJSONIO::fromJSON(U), rjson::fromJSON(U))
# Unit: microseconds
#                   expr     min       lq   median       uq      max
# 1   rjson::fromJSON(U)  94.788 100.8650 105.6035 111.0740 3457.479
# 2 RJSONIO::fromJSON(U) 520.131 527.7775 533.2715 555.2415  942.136

使用 iris dataset的示例2

Iris.JSON <- toJSON(iris)

microbenchmark(RJSONIO::fromJSON(Iris.JSON), rjson::fromJSON(Iris.JSON))
# Unit: microseconds
#                           expr      min       lq   median       uq       max
# 1   rjson::fromJSON(Iris.JSON)  229.669  235.571  238.511  241.423   260.164
# 2 RJSONIO::fromJSON(Iris.JSON) 1209.607 1224.793 1232.165 1238.953 12039.772

> sessionInfo()
R version 2.15.1 (2012-06-22)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] data.table_1.8.8 stringr_0.6.1    RJSONIO_1.0-1    rjson_0.2.11

loaded via a namespace (and not attached):
[1] plyr_1.7.1
EN

回答 2

Stack Overflow用户

发布于 2015-12-02 08:21:42

> library('BBmisc')
> suppressAll(lib(c('RJSONIO','rjson','jsonlite','microbenchmark')))
> U <- toJSON(list(1:10, LETTERS, letters, rnorm(20)))
> microbenchmark(
+     rjson::toJSON(U),
+     RJSONIO::toJSON(U),
+     jsonlite::toJSON(U, dataframe = "column"),
+     times = 10
+ )
Unit: microseconds
                                      expr     min      lq      mean   median      uq       max neval cld
                          rjson::toJSON(U)  65.174  68.767 2002.7007  88.2675 103.151 19179.224    10   a
                        RJSONIO::toJSON(U) 299.186 304.832  482.8038 329.7210 493.683  1351.727    10   a
 jsonlite::toJSON(U, dataframe = "column") 485.985 501.381  555.4192 548.5935 587.083   708.708    10   a

测试system.time()

> microbenchmark(
+     system.time(rjson::toJSON(U)),
+     system.time(RJSONIO::toJSON(U)),
+     system.time(jsonlite::toJSON(U, dataframe = "column")),
+     times = 10)
Unit: milliseconds
                                                   expr      min       lq     mean   median       uq      max neval cld
                          system.time(rjson::toJSON(U)) 112.0660 115.8677 119.8426 119.8372 121.6908 132.2111    10  ab
                        system.time(RJSONIO::toJSON(U)) 115.4223 118.0262 129.2758 120.5690 148.5175 151.6874    10   b
 system.time(jsonlite::toJSON(U, dataframe = "column")) 113.2674 114.9096 118.0905 117.8401 120.9626 123.6784    10  a

下面是几个包的比较。希望这些链接能帮到你。

1) New package: jsonlite. A smart(er) JSON encoder/decoder.

2) Improved memory usage and RJSONIO compatibility in jsonlite 0.9.15

3) A biased comparsion of JSON packages in R

票数 1
EN

Stack Overflow用户

发布于 2017-03-28 14:49:18

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15308435

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档