1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- #include "socketio.hpp"
- #include "crypt/BigInt64.hpp"
- #include <xoshiro.hpp>
- #include <iostream>
- #include <chrono>
- #include <algorithm>
- #include <numeric>
- xoshiro_256 gen(42);
- unsigned long long nanoTime(){
- using namespace std;
- using namespace std::chrono;
- return duration_cast<nanoseconds>(high_resolution_clock::now().time_since_epoch()).count();
- }
- template<typename T>
- std::ostream& operator<<(std::ostream& out, std::vector<T> o){
- out << "[";
- for(unsigned int i = 0;i < o.size();i++){
- if(o[i] == '\r')continue;
- out << o[i];
- if(i < o.size() - 1)
- out << ", ";
- }
- return out << "]";
- }
- template<>
- std::ostream& operator<< <char>(std::ostream& out, std::vector<char> o){
- for(unsigned int i = 0;i < o.size();i++){
- out << o[i];
- }
- return out;
- }
- unsigned long long multTest(size_t s){
- BigInt a(gen,s);
- BigInt b(gen,s);
- std::vector<unsigned long long> times(0);
- for(int o = 0;o < 4;o++){
- auto t1 = nanoTime();
- for(int i = 0;i < 1000;i++){
- a = a.mult(b);
- a.cut(s);
- }
- auto t2 = nanoTime();
- times.push_back((t2 - t1));
- }
- std::sort(times.begin(), times.end());
- /*for(auto t : times){
- std::cout << t/1000 << ", ";
- }*/
- //std::cout << std::endl;
- return std::accumulate(times.begin(), times.end(), 0ULL);
- }
- int mailn(){
- BigInt a("4528437659827");
- BigInt b(gen, 31);
- BigInt res = a.modPow(b, secure_prime);
- std::cout << res.toString() << std::endl;
- //return 0;
- multTest(50);
- //multTest(100);
- //multTest(200);
- std::cout << multTest(50 ) / 1000 / 1000 << " ms" << std::endl;
- std::cout << multTest(100) / 1000 / 1000 << " ms" << std::endl;
- std::cout << multTest(200) / 1000 / 1000 << " ms" << std::endl;
- std::cout << multTest(400) / 1000 / 1000 << " ms" << std::endl;
- //std::cout << multTest(800) / 1000 / 1000 << " ms" << std::endl;
- }
- int main(){
- cppsocket sock("127.0.0.1", 80);
- //cppsocket sock("127.0.0.1", 80);
- std::vector<char> toSend(10);
- for(unsigned int i = 0;i < toSend.size();i++){
- toSend[i] = (char)(i * i) % 10 + 'a';
- }
- //std::cout << errno << std::endl;
- try{
- for(int i = 0;i < 100;i++){
- sock.write(toSend);
- std::cout << "Rec" << std::endl;
- std::cout << sock.receive() << std::endl;
- //std::this_thread::sleep_for(std::chrono::milliseconds(1));
- }
- }
- catch(std::exception& e){
- std::cout << e.what() << std::endl;
- }
- //std::cout << "Sent " << std::to_string(toSend.size()) << ", Receiving..." << std::endl;
- //sock.write(std::vector<char>(1,1));
- //std::vector<char> vec = sock.receive();
- //std::cout << (vec == toSend);
- //std::cout << vec << std::endl;
- //vec = sock.receive();
- //std::cout << vec << std::endl;
- return 0;
- }
|