if I’ll call my own R package in julia… is my r code will run fast as C?
I’m guessing here my r code running in julia jit compiler?
please answer me… please
Your question isn’t entirely clear, but I interpret it as “if I use RCall
to call a package written in R from Julia, will Julia make it faster by compiling it?”
The answer to this question is no: if you use RCall to run code in R from Julia, it will run at the same speed it would have run if you used R directly. You can think of RCall
as a convenience package that handles the transfer of data back and forth between a Julia and an R process, but any R computations are run in the R process, so there shouldn’t be any changes to runtime speed (modulo some small overhead potentially for passing data).
okay… I made R package with juliacall(basically i call my julia code in R) So according to you my julia code run in julia jit compiler… but it is slow I measured the performance why this is happening
Sorry I’m not sure I understand - now you’re saying you’re calling Julia code in R, not the other way around? Or are you calling R code using RCall
in a Julia package, which you then call from R again via JuliaCall
?
In principle I would expect runtimes using JuliaCall to be the same as when you call the Julia code in Julia (maybe plus a little overhead for shuffling data around), are you finding that that’s not the case?
There could be many reasons for this, generally impossible to say without code.
First, I would make sure that code is fast when run with Julia directly.
sum() takes 160 microsecond → this is R function
j$sum0() takes 7 milisecond → this is julia function
I’m using here juliaconnectoR package
and juliacall is slower than juliaconnector it takes around 8-9 milisecond
I mean sure, running functions that take on the order of milliseconds or less to execute is probably not the best use case for cross-language interoperability - I’m not surprised that overhead for this kind of operation is noticeable.
yeah I agree convert R object to julia object takes some time even Rcpp(c++ interface with R) takes 784 microsecond but atleast it should take time same as rcpp.
if I run this same function directly in julia REPL fast
Note that your benchmark here includes compilation time - you should use BenchmarkTools
and the @btime
macro to get a more precise estimate of runtime in Julia.