I incorporated C++ shared library generated from MATLAB in a Win32 console application. The MATLAB program takes 2-3 sec to execute in MATLAB but the console application takes 11-12 seconds to execute. I read this is because of the start up time of MCR and I believe after the MCR is initialized it must take same time as it takes in matlab. So how can I load or initialize the MCR so that it is always in the RAM or cache so that it will take 2-3 sec for the console application to run? Should I have to make an infinity loop so that the MCR is loaded continously?? I am working on Windows OS and I am calling the console application from PHP. Any tutorials or link for that? 

I have added the MCR\_CACHE\_ROOT as an environment variable which points to a folder(not temporary). My console application code is as follows:

```
// shoes_shared.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "shoes_sharedlibrary.h"
#include <iostream>
#include <string.h>
#include "mex.h"

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    /* Call the MCR and library initialization functions */
 //const char *pStrings[]={"-nojvm","-nojit"};
 //   if (!mclInitializeApplication(pStrings,2))
 //   {
 //       fprintf(stderr, "Could not initialize MCR for the application.\n");
 //       return -1;
 //   }

if (!shoes_sharedlibraryInitialize())
{

    exit(1);
}

     mwArray img(argv[1]); 

     double wt1 = _tstof(argv[2]);
     mwArray C(wt1);
    double wt2 = _tstof(argv[3]);
    mwArray F(wt2);
    double wt3 = _tstof(argv[4]);
    mwArray T(wt3);
    double wt4 = _tstof(argv[5]);
    mwArray S(wt4);

           test_shoes(img,C,F,T,S);
            //shoes_sharedlibraryTerminate();
            //mclTerminateApplication();
            return 0;
}

```

I have commented the lines above thinking that it will make it faster but no luck. Any help?