// BEGIN mycpp output #include "mycpp/runtime.h" GLOBAL_STR(str0, "Wrote %d bytes to StringIO"); GLOBAL_STR(str1, "contents = %s ... %s"); GLOBAL_STR(str2, "contents = %s ... %s"); GLOBAL_STR(str3, "stdout\n"); GLOBAL_STR(str4, "Ran %d iterations"); GLOBAL_STR(str5, "result = %d"); namespace files { // forward declare } // forward declare namespace files namespace files { // declare void run_tests(); void run_benchmarks(); } // declare namespace files namespace files { // define void run_tests() { mylib::BufWriter* f = nullptr; BigStr* contents = nullptr; mylib::Writer* f2 = nullptr; f = Alloc(); for (int i = 0; i < 30; ++i) { f->write(chr((i + 65))); } contents = f->getvalue(); mylib::print_stderr(StrFormat("Wrote %d bytes to StringIO", len(contents))); if (1) { mylib::print_stderr(StrFormat("contents = %s ... %s", contents->slice(0, 10), contents->slice(-10))); } f2 = mylib::Stdout(); f2->write(str3); } void run_benchmarks() { int n; int result; int i; mylib::BufWriter* f = nullptr; n = 10000; result = 0; i = 0; while (i < n) { f = Alloc(); for (int j = 0; j < 30; ++j) { f->write(chr((j + 65))); } result += len(f->getvalue()); mylib::MaybeCollect(); i += 1; } mylib::print_stderr(StrFormat("Ran %d iterations", n)); mylib::print_stderr(StrFormat("result = %d", result)); } } // define namespace files