Advertisement
Guest User

Untitled

a guest
Sep 10th, 2014
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include "md5.h"
  4. #include <thread>
  5.  
  6. using namespace std;
  7. MD5 md5;
  8. const string CHARACTERS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  9. char randstring[32];
  10.  
  11. string RandomString() {
  12.  
  13. srand((unsigned int)time(NULL));
  14. for (int i = 0; i<32; i++) {
  15. randstring[i] = CHARACTERS[rand() % 62];
  16. }
  17. return randstring;
  18. }
  19.  
  20. void LoopMD5() {
  21. for (int i = 0; i<500000; i++) {
  22. md5(RandomString());
  23. }
  24. }
  25.  
  26. int main() {
  27. time_t time_start = time(0);
  28.  
  29. thread t1(LoopMD5);
  30. thread t2(LoopMD5);
  31.  
  32. t1.join();
  33. t2.join();
  34.  
  35. time_t time_end = time(0);
  36. time_t execution_time = (time_end - time_start);
  37.  
  38. cout << "Content-type:text/html\r\n\r\n";
  39. cout << "<!DOCTYPE html>\n";
  40. cout << "<html>\n";
  41. cout << "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n";
  42. cout << "<meta charset=\"UTF-8\">\n";
  43. cout << "<title>Test C++ Threaded Page</title>\n";
  44. cout << "<link href=\"http://fonts.googleapis.com/css?family=Open+Sans:400,400italic,700,700italic&amp;subset=latin,latin-ext,cyrillic-ext\" rel=\"stylesheet\" type=\"text/css\">\n";
  45. cout << "<link rel=\"stylesheet\" href=\"/css/style.css\">\n";
  46. cout << "</head>\n";
  47. cout << "<body>\n";
  48. cout << "<div class=\"page-wrapper\">\n";
  49. cout << "<div id=\"page-content\">This shit had " << execution_time << " seconds to execute</div>\n";
  50. cout << "</div>\n";
  51. cout << "</body>\n";
  52. cout << "</html>\n";
  53.  
  54. return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement