daily pastebin goal
75%
SHARE
TWEET

Untitled

a guest Mar 13th, 2018 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. compiler::enableJIT(0)
  2. compiler::enableJIT(0)
  3.  
  4. rustinr::rust(code = '
  5. // #[rustr_export]
  6. pub fn fib_rust(a : i32) -> RResult<f64>{
  7.     let mut first  = 0.0;
  8.     let mut second = 1.0;
  9.     let mut third  = 0.0;
  10.     for _ in 0..a {
  11.         third = first + second;
  12.         first = second;
  13.         second = third;
  14.     }
  15.     Ok(first)
  16. }
  17. ')
  18.  
  19. fib_r <- function(n) {
  20.   first  <- 0
  21.   second <- 1
  22.   third  <- 0
  23.   for (i in seq_len(n)) {
  24.     third  <- first + second
  25.     first  <- second
  26.     second <- third
  27.   }
  28.   first
  29. }
  30.  
  31. fib_r_cmp <- compiler::cmpfun(fib_r)
  32. fib_rust  <- compiler::cmpfun(fib_rust)
  33.  
  34. stopifnot(fib_r(1000L) == fib_r_cmp(1000L))
  35. stopifnot(fib_r(1000L) == fib_rust(1000L))
  36.  
  37. microbenchmark::microbenchmark(
  38.   'r'          = fib_r(    1000L),
  39.   'r_compiled' = fib_r_cmp(1000L),
  40.   'rust'       = fib_rust( 1000L)
  41. )
  42. ## Unit: microseconds
  43. ##        expr     min       lq      mean   median       uq     max neval cld
  44. ##           r 229.796 231.2595 240.78482 232.9030 237.7065 340.625   100   c
  45. ##  r_compiled  46.829  48.0710  52.06551  49.1385  52.6400 106.518   100  b
  46. ##        rust   1.762   1.9325   2.42770   2.2695   2.4615  14.861   100 a
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top