# Performance speed of WSTP code

I have found that running the following WSTP code, using C++ (MSVS 2010, Windows 7, 32-bit) and Mathematica 11.1, takes about 0.8 Second:

clock_t t0 = clock();
WSPutFunction(link, "1", 0); // (Simply evaluating the number 1.)
clock_t t1 = clock();
double t = (double)(t1 - t0) / CLOCKS_PER_SEC;


On the line where simply the number 1 is evaluated, we wish to run a piece of Mathematica code, which takes less than 0.1 Second when running directly from Mathematica.

If even simply evaluating a constant number takes 0.8 Second, how can we expect to make the overall time taken less than 0.1 Second?

Does anyone know a way out of this problem? Thanks.

UPDATE on Thursday, May 04, 2017:

Complete code:

#include <iostream>
#include "wstp.h"
#include <time.h>
using std::cin; using std::cout; using std::endl;
static void init_and_open_link(int argc, char **argv);
int main(int argc, char **argv){
clock_t t0 = clock();
clock_t t1 = clock();
double t = (double)(t1 - t0) / CLOCKS_PER_SEC;
cout << "t = " << t << " seconds." << endl;
return 0;}
static void deinit(void){if(env) WSDeinitialize(env);}

• If you have not seen it yes, look at this tutorial: edenwaith.com/development/tutorials/mathlink/ML_Tut.pdf I do not think that WSPutFunction(link, "1", 0); is correct syntax. PutSymbol is used for putting the head of an expression as a symbol. 1 is not a valid symbol name. Maybe you meant WSPutInteger. I do not know what would happen if you do this. In the best case it puts 1[] (which is not 1), in the worst cases it messes up your link. May 4, 2017 at 9:09
• If you really want to send 1[], I believe you have to start with WSPutType. May 4, 2017 at 9:14