Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Switch function in Mata?

    In an effort to speed up my code I was recommended to replace my lengthy if and else if statements into switch commands. However, I could not find the switch command in Mata. Does it actually exist?

    Thanks a lot!

    Peter

  • #2
    As far as I know the answer is negative. And I could not find in the documentation any switch or case statement.

    Comment


    • #3
      OK thanks a lot. That's what I thought!

      Comment


      • #4
        Honest questions.

        Would a switch or case function really execute faster?

        What is the magnitude of speed-up that you expect?

        Best
        Daniel

        Comment


        • #5
          Well I am in general investigating, how to speed up my code. Since the if-statements are within a long loop, even a small difference per execution would make a large difference in the entire running time.

          Comment


          • #6
            Peter Thesling are you able to share what you've tried thus far? Perhaps there are other inefficiencies that could be addressed to get you the performance gains you're after without having to modify your logic as much.

            Comment


            • #7
              You can use the ternary operator (type "help [M-2] op_conditional"), but I don't see any reason to expect that to offer a speedup vs if-else.

              Comment

              Working...
              X