test.cpp 1.9 KB

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