#define _GNU_SOURCE 1 #include #include #include struct S { S () : end (buffer) {} ~S () { fwrite_unlocked (buffer, end - buffer, 1, stdout); } #if VERSION == 3 void __attribute__((noinline)) #else void #endif write (const char *x, size_t len) { if (__builtin_expect (buffer + sizeof (buffer) - end < len, 0)) { fwrite_unlocked (buffer, end - buffer, 1, stdout); end = buffer; } memcpy (end, x, len); end += len; } #if VERSION == 1 || VERSION == 3 template void write (const char (&x)[N]) { write (x, N - 1); } #elif VERSION == 2 template void __attribute__((noinline)) write (const char (&x)[N]) { write (x, N - 1); } #else void __attribute__((noinline)) write (const char *x) { write (x, strlen (x)); } #endif char buffer[4096]; char *end; }; int main () { S s; for (int i = 0; i < 100000000; ++i) { #if VERSION <= 4 s.write ("Hello!"); #elif VERSION == 5 fputs_unlocked ("Hello!", stdout); #elif VERSION == 6 fwrite_unlocked ("Hello!", 6, 1, stdout); #elif VERSION == 7 std::cout << "Hello!"; #else #error Please define VERSION #endif } return 0; }