Ad
  • Default User Avatar

    conversion to string and lookup in it can't be efficient

  • Default User Avatar

    thanks for the reply. I tend to write code as clean as possible so that it is understandable. I haven't had a case where I needed to optimize my code, but this should help when that day comes.

  • Custom User Avatar

    In general, less code is always better. Less to maintain, less to go wrong. Also, the compiler does some optimisation when it sees these patterns to run them in the most efficient way.

    There are some rare cases where you will need to write optimised code yourself because the compiler doesn't know how to optimise them. One example I can think of is nested loops.

  • Default User Avatar

    clever. I'm curious in general, is code more efficient during runtime when it is coded like this as opposed to a more verbose method?

    either way, nice solution