小编Dav*_*cia的帖子

使用Rcpp的代码比使用g ++编译的代码运行得更快

我运行的是完全相同的代码在两个方面:与编译它g++的编译器,以及调用它RRcpp.事实证明,当我运行它时,它运行速度快了近4倍R.

为什么会这样?是因为使用的编译器Rcpp不同吗?

这是我正在运行的代码c++:

#include <iostream>
#include <nlopt.hpp>
#include <time.h>
using namespace std;


int main()
{

  //--------------------------------//
  //         Initialization         //
  //--------------------------------//

  // Grid for x
  const int nx              = 60000;

  float xgrid[nx];
  const float xstep = 4 /(nx - 1);
  float it = 0;

  for(int i = 0; i < nx; i++){
    xgrid[i] = it*xstep;
    it++;
  }

  // Initialize value function V
  size_t sizeV     = nx*sizeof(float);
  float *V;
  V …
Run Code Online (Sandbox Code Playgroud)

performance r g++ rcpp

6
推荐指数
1
解决办法
119
查看次数

标签 统计

g++ ×1

performance ×1

r ×1

rcpp ×1