[R] rJava call performance

Dmitriy Lyubimov dlieu.7 at gmail.com
Fri Mar 16 23:27:38 CET 2012


PS caching reference to the class doesn't change anything fundamentally:

clazz <- J("java.lang.Double")
system.time( for( i in 1:1000) clazz$ parseDouble(as.character(i)))
   user  system elapsed
  3.788   0.000   3.790

Java parsing is slow??? nope, still looking pretty appalling for what it does:

> clazz <- J("java.lang.Math")
> system.time( for( i in 1:1000) clazz$abs(i) )
   user  system elapsed
  3.492   0.000   3.497


On Fri, Mar 16, 2012 at 3:17 PM, Dmitriy Lyubimov <dlieu.7 at gmail.com> wrote:
> Hello,
>
> I am getting pretty poor rJava call performance
>
>
>> system.time(for (i in 1:1000) J("java.lang.Double")$parseDouble(as.character(i)))
>   user  system elapsed
>  4.884   0.000   4.900
>
>
> i.e. 5 milliseconds per very simple call on a very fast cpu. JNI calls
> themselves are said to be pretty fast nowadays (10...40ns). It
> probably goes accross reflection but still doing pretty much nothing
> useful in 5ms is horrible benchmark.
>
> Is that expected rJava performance? Cause if it is, this means it is
> completely usuitable for exchanging data with Java. ( I can probably
> bulk up data in data frames and pass it as a single call to do
> something with it but then either way i have to do conversion between
> bulk of R objects and bulk of java objects).
>
> Is there's a good performant way to do passing of data.frame's between
> java and back without having to do a native call for every row?
>
> Thank you.
> -Dmitriy



More information about the R-help mailing list