#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include int makeSocket() { int sockfd; if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { perror("socket failed"); exit(EXIT_FAILURE); } return sockfd; } void connectTo(int sock, const char* host, int port) { struct sockaddr_in serv_addr; serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = inet_addr(host); serv_addr.sin_port = htons(port); if (connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) { perror("Connection failed"); exit(EXIT_FAILURE); } printf("Connected to %s: %d\n", host, port); } int main(int argc, char* argv[]) { int socket = makeSocket(); connectTo(socket, "127.0.0.1", 7777); //allocating 100 megabytes of memory uint64_t* chunky_boy = new uint64_t[13107200]; size_t chunky_boy_size = 13107200 * sizeof(uint64_t); printf("chonky size %d", static_cast(chunky_boy_size)); sleep(5); //setting memory to verify non-emptyness memset(chunky_boy, 45678832, chunky_boy_size); std::vector sizes; std::vector times; for ( int i = 1; i < 1e6 + 2; i += 1e3) { printf("Selected buffer size: %d\n", i); auto start = std::chrono::high_resolution_clock::now(); int kilos = 0; for ( int j = 0; j < chunky_boy_size; ) { ssize_t bytes = send(socket, reinterpret_cast(chunky_boy) + j, std::min(static_cast(chunky_boy_size) - j, i), 0); j += i; if (j%1024 == 0) { kilos++; } } auto end = std::chrono::high_resolution_clock::now(); double time_taken = std::chrono::duration_cast(end - start).count(); time_taken *= 1e-9; times.push_back(time_taken); sizes.push_back(i); std::cout << "Time taken by program is : " << std::fixed << time_taken << std::setprecision(9); std::cout << " sec" << std::endl; } std::ofstream fout; fout.open("send_data_buffer"); fout << "buffer_size;time;\n"; auto iter_sizes = sizes.begin(); auto iter_times = times.begin(); for ( ; (iter_sizes != sizes.end()) && (iter_times != times.end()) ; (++iter_sizes, ++iter_times) ) { fout << *iter_sizes << ";" << *iter_times << ";\n"; } fout.close(); return 0; }