#include #include #include #include #include #define NUM_ITERATIONS (1000000) int main() { const char *str1 = "2020-04-24T15:56:32.069998Z 8 [Note] [MY-010914] [Server] Aborted connection 8 to db: 'unconnected' user: 'root' host: 'localhost' (Got an error reading communication packets)."; //same as above but with newline to end with const char *str2 = "2020-04-24T15:56:32.069998Z 8 [Note] [MY-010914] [Server] Aborted connection 8 to db: 'unconnected' user: 'root' host: 'localhost' (Got an error reading communication packets).\n"; //test what MySQL function log_write_errstream does: auto start = std::chrono::high_resolution_clock::now(); for (int i = 0; i < NUM_ITERATIONS; i++) { int lengt1 = strlen(str1); fprintf(stderr, "%.*s\n", lengt1, str1); fflush(stderr); } auto finish = std::chrono::high_resolution_clock::now(); std::chrono::duration elapsed1 = finish - start; //test what should be faster start = std::chrono::high_resolution_clock::now(); for (int i = 0; i < NUM_ITERATIONS; i++) { fputs(str2, stderr); fflush(stderr); } finish = std::chrono::high_resolution_clock::now(); std::chrono::duration elapsed2 = finish - start; std::cout << "fprintf elapsed time: " << elapsed1.count() << " seconds\n"; std::cout << "fputs elapsed time : " << elapsed2.count() << " seconds\n"; return 0; }