C++ w/ promise 124ms <92.14%, 9.4MB <100%
Runtime: 124 ms, faster than 92.14% of C++ online submissions for Print in Order.\n* Memory Usage: 9.4 MB, less than 100.00% of C++ online submissions for Print
* Runtime: 124 ms, faster than 92.14% of C++ online submissions for Print in Order.\n* Memory Usage: 9.4 MB, less than 100.00% of C++ online submissions for Print in Order.\n\nThis is a simple task. I did try writing one solution with a condition_variable and one using future/promise.\nThe performance was fairly close, with promise performing slightly better.\n\nIf the task was larger in some dimension, I could walk through the program to show where time is being wasted.  This is as simple as it gets and there ought to be a tight cluster of results, where relative performance is honestly random.\n\nMy reason for using promise is that it avoids synchronizing mutex locks between many threads, but there isn\'t much tradeoff between memory or performance no matter what you choose.\n\n```\nclass Foo {\npublic:\n    Foo() {}\n\n    void first(function<void()> printFirst) {\n        \n        // printFirst() outputs "first". Do not change or remove this line.\n        printFirst();\n        p1.set_value(1);\n    }\n\n    void second(function<void()> printSecond) {\n        p1.get_future().wait();\n        // printSecond() outputs "second". Do not change or remove this line.\n        printSecond();\n        p2.set_value(1);\n    }\n\n    void third(function<void()> printThird) {\n        p2.get_future().wait();\n        // printThird() outputs "third". Do not change or remove this line.\n        printThird();\n    }\n    \n    promise<bool> p1;\n    promise<bool> p2;\n};\n```\n
['C']