Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Condensed, yes. But also not easy on the eyes :)
After
-O2
got introduced to C++ runner, some kata started timing out on compilation. It turned out that large amounts of strings initialized with literals take forever to compile. Large LUTs or precomputed answers or large string inputs used by tests made compilation times skyrocket.I can't remember the exact conclusion but I think that using std::string_view or c-strings helped in such cases.
A lot of assembly code is produced thanks to the inclusion of
std::string
literals andstd::map
usage.Using Clang 8 and
O2
optimization level (same environment as CW) my solution produces 515 lines of assembly, hundreds of which are just setting up the program state. Switching from strings to enums reduces it to 136 lines of assembly, half of which, again, simply create a(State, Event) -> State
mapping.Note that terse code does not always translate to good performance. Compare this code at:
https://godbolt.org/
with fx my code that uses char const* inside the FSM with a simple if / else.
The difference in assembly lines is:
370 vs >1800.
(Though this does not necessarily mean the same scaling in performance).
Watch out! You do not allocate enough space for the struct in the general case. You allocate only for the size of the pointer, which is a constant (probably 8 bytes here).
This comment is hidden because it contains spoiler information about the solution