Do not use return, break, exit or continue

Return, break, exit, continue and throw are implemented using C++ exception.

C++ exceptions are SLOW!

TEST CASES:

   fn test1a v = (if v == true do return 1; 0)
   fn test1b v = (if v == true then 1 else 0)

FOR 100,000 ITERATIONS:

   test1a true  -- 15890 msec.
   test1a false  -- 78 msec.
   test1b true  -- 47 msec.
   test1b false  -- 62 msec.

TEST CASES:

   fn test2a =
   (
     local res
     for i = 1 to 1000 do
       if i == 10 do (res = i; break;)
     res
   )

   fn test2b =
   ( 
     local notfound = true, res
     for i = 1 to 1000 while notfound do
       if i == 10 do (res = i; notfound = false;)
     res
   )

FOR 100,000 ITERATIONS:

   test2a()   -- 84265 msec.
   test2b()   -- 1359 msec.

Previous Tip

matchPattern is faster than findString

Next Tip

Use StringStream to build large strings