Conclusion

I thought the outcome stays the same. Sometimes, when I make another run on approximating \(\pi\), C is the fastest while sometimes FORTRAN is the fastest, or otherwise, C++ is surely the fastest.

The remarks that I am sure for this example:

  1. R or Python shares the outcome: As I thought, written in vanilla will be so slow. In fact, Python Vanilla is the slowest among them.
    • However, you can’t just avoid loops from these languages.
    • They’re FAST, although the other languages are just compiled.
  2. The Rust language, as I conclude, not so excellent to be used in computing. Or maybe perhaps, the Rust code I wrote is just not optimized.
    • Same thing for other languages, especially Julia, although Julia is exceptionally fast.
  3. If you want a code for speed of execution, C++ is the perfect language to be used since in fact, with Rcpp, you can easily wrap it into R as R being interpreter.
    • C++ is the fastest in some application here.
      • Recursive Fibonacci Sequence
      • Moving Average
      • Convolution

So here’s my take:

  • Surely that C++ code is only code that can make R code faster. Among the lower languages (C, C++, FORTRAN, Rust), C++, with Rcpp, is the easiest language to compile, but you will be bothered to need to write a boilerplate C++ code in order to work.
  • C/FORTRAN code makes the solution the more boilerplate. In fact, what you saw in C and FORTRAN codes are called “subroutines”. My experience is that for C, you need to use pointers or S expressions (SEXP) in order to be callable.
  • Use vectorized operations or parallel computing to if you want to make the code of your tasks more faster.
    • You can use the base functions in R since their source code is actually written in C/FORTRAN.
    • NumPy is the best library in Python for vectorized operations.