fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <ctime>
  4. #include <cstdlib>
  5. #include <boost/pool/pool_alloc.hpp>
  6.  
  7. __attribute__ ((noinline))
  8. int nofunc(int count) {
  9. return count;
  10. }
  11.  
  12. __attribute__ ((noinline))
  13. int allocatorfunc(int count) {
  14. char* a = new char[count];
  15. a[count-1] = (char)count;
  16. int nocheat = a[count-1];
  17. delete[] a;
  18. return nocheat;
  19. }
  20.  
  21. __attribute__ ((noinline))
  22. int allocafunc(int count) {
  23. char* a = (char*)alloca(count);
  24. a[count-1] = (char)count;
  25. int nocheat = a[count-1];
  26. return nocheat;
  27. }
  28.  
  29. __attribute__ ((noinline))
  30. int poolfunc(int count) {
  31. boost::pool_allocator<char> p;
  32. char* a = p.allocate(count);
  33. a[count-1] = (char)count;
  34. int nocheat = a[count-1];
  35. p.deallocate(a);
  36. return nocheat;
  37. }
  38. int main() {
  39. #ifdef _DEBUG
  40. int count=100000;
  41. #else
  42. int count=10000000;
  43. #endif
  44. int nocheat = 0;
  45. clock_t begin = 0;
  46.  
  47. typedef int (*funcptr)(int);
  48. funcptr functions[3] = {nofunc, allocatorfunc, allocafunc};
  49. char* names[3] = {"nofunc", "allocator", "alloca"};
  50.  
  51. try {
  52. for(int j=0; j<3; ++j) {
  53. srand(0);
  54. nocheat = 0;
  55. begin = clock();
  56. for(int i=0; i<count; ++i)
  57. nocheat += functions[j](1+rand()%4000);
  58. double overhead = double(clock()-begin)/CLOCKS_PER_SEC;
  59. std::cout << names[j] << " took " << overhead << " (" << nocheat << ")\n";
  60. }
  61. } catch(std::exception& e) {
  62. std::cout << e.what();
  63. throw;
  64. }
  65.  
  66. return 0;
  67. }
Compilation error #stdin compilation error #stdout 2.15s 2960KB
stdin
Standard input is empty
compilation info
prog.cpp:5:37: fatal error: boost/pool/pool_alloc.hpp: No such file or directory
compilation terminated.
stdout
Standard output is empty