test.cpp 2.1 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(8);
  33. //a[0] >>= 30;
  34. BigInt x(4,0);
  35. x.adda(a);
  36. x.bitshiftRight(1);
  37. std::cout << x.bitDifference(a) << std::endl;
  38. //std::cout << a.toString() << std::endl;
  39. a.bitshiftLeft(1);
  40. //std::cout << a.toString() << std::endl;
  41. return 0;
  42. for(unsigned int i = 2;true;i *= 2){
  43. BigInt a(gen, i);
  44. BigInt b(gen, i);
  45. auto t1 = nanoTime();
  46. a = a.mult(b);
  47. auto t2 = nanoTime();
  48. std::cout << i << ", " << ((double)((t2 - t1) / 1000) / 1000.0d) << " ms \t\t" << (std::hash<BigInt>()(a) % 10) << std::endl;
  49. }
  50. }
  51. int mian(){
  52. cppsocket sock("192.168.178.79", 80);
  53. //cppsocket sock("127.0.0.1", 80);
  54. std::vector<char> toSend(10);
  55. for(unsigned int i = 0;i < toSend.size();i++){
  56. toSend[i] = (char)(i * i) % 10 + 'a';
  57. }
  58. //std::cout << errno << std::endl;
  59. try{
  60. for(int i = 0;i < 100;i++){
  61. sock.write(toSend);
  62. std::cout << "Rec" << std::endl;
  63. std::cout << sock.receive() << std::endl;
  64. //std::this_thread::sleep_for(std::chrono::milliseconds(1));
  65. }
  66. }
  67. catch(std::exception& e){
  68. std::cout << e.what() << std::endl;
  69. }
  70. //std::cout << "Sent " << std::to_string(toSend.size()) << ", Receiving..." << std::endl;
  71. //sock.write(std::vector<char>(1,1));
  72. //std::vector<char> vec = sock.receive();
  73. //std::cout << (vec == toSend);
  74. //std::cout << vec << std::endl;
  75. //vec = sock.receive();
  76. //std::cout << vec << std::endl;
  77. return 0;
  78. }