ChipMaster's trial hacks on C++CMS starting with v1.2.1. Not sure I'll follow on with the v2 since it looks to be breaking and mostly frivolous.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

126 lines
3.5 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (C) 2008-2012 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
  4. //
  5. // See accompanying file COPYING.TXT file for licensing details.
  6. //
  7. ///////////////////////////////////////////////////////////////////////////////
  8. #include "test.h"
  9. #include "cache_storage.h"
  10. #include "base_cache.h"
  11. #include <booster/intrusive_ptr.h>
  12. #include <booster/posix_time.h>
  13. #include <cppcms/config.h>
  14. #include <iostream>
  15. #include <booster/auto_ptr_inc.h>
  16. #include <time.h>
  17. #include <iomanip>
  18. #include <stdlib.h>
  19. #include <cppcms/urandom.h>
  20. extern "C" void do_store( cppcms::impl::base_cache &c,
  21. std::string const &key,
  22. std::string const &value,
  23. std::set<std::string> const &tr)
  24. {
  25. c.store(key,value,tr,time(0)+1000);
  26. }
  27. unsigned long long rand_val()
  28. {
  29. cppcms::urandom_device rd;
  30. unsigned long long v;
  31. rd.generate(&v,sizeof(v));
  32. return v;
  33. }
  34. void cache_tester(booster::intrusive_ptr<cppcms::impl::base_cache> cache)
  35. {
  36. std::string page;
  37. page.reserve(16384);
  38. while(page.size() < 16384) {
  39. page+="x";
  40. }
  41. unsigned long long rnd[10][10];
  42. for(int i=0;i<10;i++)
  43. for(int j=0;j<10;j++)
  44. rnd[i][j]=rand_val();
  45. int limit = 10000;
  46. double store = 0;
  47. double store2 = 0;
  48. int store_count=0;
  49. double rise = 0,rise2=0;
  50. int rise_count=0;
  51. for(int i=0;i<limit;i++) {
  52. std::string key;
  53. std::set<std::string> triggers;
  54. for(int j=0;j<10;j++) {
  55. std::ostringstream ss;
  56. ss << "trigger_" << j <<"_" << i % 10;
  57. //ss << "t" << rnd[j][i % 10];
  58. triggers.insert(ss.str());
  59. }
  60. std::ostringstream ss;
  61. ss << "key_" << i;
  62. //ss << rand_val();
  63. key=ss.str();
  64. {
  65. booster::ptime start = booster::ptime::now();
  66. do_store(*cache,key,page,triggers);
  67. //cache->store(key,page,triggers,time(0)+100);
  68. booster::ptime end = booster::ptime::now();
  69. double m = booster::ptime::to_number(end-start);
  70. store +=m;
  71. store2 += m*m;
  72. store_count ++;
  73. }
  74. if(i % 1000 == 999) {
  75. std::ostringstream ss;
  76. ss << "trigger_0_" << ((i + 324) % 10000 / 1000);
  77. //ss << "t" << rnd[0][((i + 324) % 10000 / 1000)];
  78. std::string t=ss.str();
  79. {
  80. booster::ptime start = booster::ptime::now();
  81. cache->rise(t);
  82. booster::ptime end = booster::ptime::now();
  83. double m = booster::ptime::to_number(end-start);
  84. rise +=m;
  85. rise2 += m*m;
  86. rise_count ++;
  87. }
  88. }
  89. }
  90. double mean_store = store / store_count * 1e6;
  91. double std_store = sqrt(store2 / store_count - (store / store_count) * ( store / store_count)) * 1e6;
  92. std::cout <<std::fixed<< "Store " <<std::setprecision(1)<< std::setw(16)<< mean_store << " +/- " <<std::setw(16)<< std_store << std::endl;
  93. double mean_rise = rise / rise_count * 1e6;
  94. double std_rise = sqrt(rise2 / rise_count - (rise / rise_count) * ( rise / rise_count)) * 1e6;
  95. std::cout << "Rise " <<std::setprecision(1)<<std::setw(16)<< mean_rise << " +/- " <<std::setw(16)<< std_rise << std::endl;
  96. }
  97. int main()
  98. {
  99. try {
  100. std::locale::global(std::locale(""));
  101. std::cout.imbue(std::locale());
  102. std::cout << "Testing thread cache... "<< std::endl;
  103. cache_tester(cppcms::impl::thread_cache_factory(10000));
  104. #if !defined(CPPCMS_WIN32) && !defined(CPPCMS_NO_PREFOK_CACHE)
  105. std::cout << "Testing process cache... " << std::endl;
  106. cache_tester(cppcms::impl::process_cache_factory(512*1024*1024,10000));
  107. #endif
  108. }
  109. catch(std::exception const &e) {
  110. std::cerr << "\nFail " << e.what() << std::endl;
  111. return 1;
  112. }
  113. return 0;
  114. }