Hi,

I did a simple experiment to profile the performance of dynamic linking vs 
static linking and found that dynamic linking is 10x slower than static 
linking. Is this slowdown expected for dynamic linking?

This is my main.cpp:

---------------------------------------------------------------------------------------------------------------------
#include <stdio.h>
#include <chrono>
#include <iostream>

using namespace std;
using namespace std::chrono;

class input {
public:
      int* m_test;
};

extern int sidey(input object, char* str, int num);


int main() {
  input i; i.m_test = new int(7);
  char* str = (char*)"test string to side";
  printf("hello from main\n");
  int count = 0, ret = 0;
  high_resolution_clock::time_point t1 = high_resolution_clock::now();
  do {
    ret = sidey(i, str, 10);
  } while (count++<1000000000);
  high_resolution_clock::time_point t2 = high_resolution_clock::now();
  auto duration = duration_cast<milliseconds>(t2-t1).count();
  cout << "Total duration:" << duration << endl;
  return ret;
}

This is my side.cpp:

---------------------------------------------------------------------------------------------------------------------
#include <stdio.h>

class input {
public:
      int* m_test;
};

int sidey(input i, char* str, int num) { 
      return *i.m_test + num + (int)str;
}

This is my link.js:

---------------------------------------------------------------------------------------------------------------------
var Module = {
  dynamicLibraries: ['side.wasm'],
};

These are my build parameters for dynamic linking:
emcc d:\git\dylink\main.cpp -O2 --profiling -o 
d:\git\dylink\build/dybuild.js -s MAIN_MODULE=1 -s WASM=1 --pre-js 
d:\git\dylink\link.js && emcc d:\git\dylink\side.cpp -O2 --profiling -o 
d:\git\dylink\build/side.js -s SIDE_MODULE=1 -s WASM=1

This is static.cpp, the file that I use to link in a side.bc:

---------------------------------------------------------------------------------------------------------------------
#include <stdio.h>
#include <chrono>
#include <iostream>

using namespace std;
using namespace std::chrono;

class input {
public:
      int* m_test;
};
extern int sidey(input object, char* str, int num);
int main() {
  input i; i.m_test = new int(7);
  char* str = (char*)"test string to side";
  printf("hello from main\n");
  int count = 0, ret = 0;
  high_resolution_clock::time_point t1 = high_resolution_clock::now();
  do {
    ret = sidey(i, str, 10);
  } while (count++<1000000000);
  high_resolution_clock::time_point t2 = high_resolution_clock::now();
  auto duration = duration_cast<milliseconds>(t2-t1).count();
  cout << "Total duration:" << duration << endl;
  return ret;
}

These are my build parameters for dynamic linking:
emcc d:\git\dylink\side.cpp -O2 --profiling -o d:\git\dylink\build/side.bc 
&& emcc d:\git\dylink\static.cpp d:\git\dylink\build/side.bc -O2 
--profiling -o d:\git\dylink\build/static.js -s WASM=1

side.cpp is the same as above.

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to