test.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #include "socketio.hpp"
  2. #include "BigInt64.hpp"
  3. #include <xoshiro.hpp>
  4. #include <iostream>
  5. #include <chrono>
  6. unsigned long long nanoTime(){
  7. using namespace std;
  8. using namespace std::chrono;
  9. return duration_cast<nanoseconds>(high_resolution_clock::now().time_since_epoch()).count();
  10. }
  11. template<typename T>
  12. std::ostream& operator<<(std::ostream& out, std::vector<T> o){
  13. out << "[";
  14. for(unsigned int i = 0;i < o.size();i++){
  15. if(o[i] == '\r')continue;
  16. out << o[i];
  17. if(i < o.size() - 1)
  18. out << ", ";
  19. }
  20. return out << "]";
  21. }
  22. template<>
  23. std::ostream& operator<< <char>(std::ostream& out, std::vector<char> o){
  24. for(unsigned int i = 0;i < o.size();i++){
  25. out << o[i];
  26. }
  27. return out;
  28. }
  29. int main(){
  30. xoshiro_256 gen(42);
  31. for(int i = 0;i < 100;i++)gen();
  32. BigInt a(gen, 2);
  33. a[0] >>= 30;
  34. BigInt x(2);
  35. std::cout << x.rawString() << std::endl;
  36. x.bitshiftLeft(64);
  37. //x.bitshiftRight(25);
  38. std::cout << x.rawString() << std::endl;// << ", " << a.rawString() << std::endl;
  39. //std::cout << a.toString() << std::endl;
  40. a.bitshiftLeft(1);
  41. //std::cout << a.toString() << std::endl;
  42. return 0;
  43. for(unsigned int i = 2;true;i *= 2){
  44. BigInt a(gen, i);
  45. BigInt b(gen, i);
  46. auto t1 = nanoTime();
  47. a = a.mult(b);
  48. auto t2 = nanoTime();
  49. std::cout << i << ", " << ((double)((t2 - t1) / 1000) / 1000.0d) << " ms \t\t" << (std::hash<BigInt>()(a) % 10) << std::endl;
  50. }
  51. }
  52. int mian(){
  53. cppsocket sock("192.168.178.79", 80);
  54. //cppsocket sock("127.0.0.1", 80);
  55. std::vector<char> toSend(10);
  56. for(unsigned int i = 0;i < toSend.size();i++){
  57. toSend[i] = (char)(i * i) % 10 + 'a';
  58. }
  59. //std::cout << errno << std::endl;
  60. try{
  61. for(int i = 0;i < 100;i++){
  62. sock.write(toSend);
  63. std::cout << "Rec" << std::endl;
  64. std::cout << sock.receive() << std::endl;
  65. //std::this_thread::sleep_for(std::chrono::milliseconds(1));
  66. }
  67. }
  68. catch(std::exception& e){
  69. std::cout << e.what() << std::endl;
  70. }
  71. //std::cout << "Sent " << std::to_string(toSend.size()) << ", Receiving..." << std::endl;
  72. //sock.write(std::vector<char>(1,1));
  73. //std::vector<char> vec = sock.receive();
  74. //std::cout << (vec == toSend);
  75. //std::cout << vec << std::endl;
  76. //vec = sock.receive();
  77. //std::cout << vec << std::endl;
  78. return 0;
  79. }