Recent posts:
Recent replies:

instead of using a magic number 10000, it would be better to use a macro $$$MaxLocalLength, see %Stream.FileBinary:ReadLine 

but remember about performance ...

/// Process private global with indirection
ClassMethod Test(val = 3) [ ProcedureBlock = 0 ]{

  s:'$d(^||addr) ^||addr(1)=1, (^(2),^(8),^(9))=289, ^(3)=3
  @("t1case" _ $g( ^||addr( val ) ) ) Q  
  
t1case1  !, "Case 1" Q
t1case3  !, "Case 3" Q
t1case289  !, "Case 2 or 8 or 9" Q
t1case  !,"Case default" Q
}

/// Local variable with indirection
ClassMethod Test2(val = 3) [ ProcedureBlock = 0 ]{

  s:'$d(addr) addr(1)=1, (addr(2),addr(8),addr(9))=289, addr(3)=3
  @( "t2case"_$g( addr( val ) ) ) Q  
  
t2case1  !, "Case 1" Q
t2case3  !, "Case 3" Q
t2case289  !, "Case 2 or 8 or 9" Q
t2case  !,"Case default" Q
}

/// Without indirection
ClassMethod Test3(val = 3) [ ProcedureBlock = 0 ]{
  if val=1 !, "Case 1" Q
  if val=3 !, "Case 3" Q
  if (val=2)!(val=8)!(val=9) !, "Case 2 or 8 or 9" Q
  !,"Case default"
}

/// Process private global without indirection
ClassMethod Test4(val = 3) [ ProcedureBlock = 0 ]{

  s:'$d(^||addr) ^||addr(1)=1, (^(2),^(8),^(9))=289, ^(3)=3
  $case($g(^||addr(val)),1:t4case1,289:t4case289,3:t4case3,:t4case)
  Q  
  
t4case1  !, "Case 1" Q
t4case3  !, "Case 3" Q
t4case289  !, "Case 2 or 8 or 9" Q
t4case  !,"Case default" Q
}

/// Local variable without indirection
ClassMethod Test5(val = 3) [ ProcedureBlock = 0 ]{

  s:'$d(addr) addr(1)=1, (addr(2),addr(8),addr(9))=289, addr(3)=3
  $case($g(addr(val)),1:t5case1,289:t5case289,3:t5case3,:t5case)
  Q  
  
t5case1  !, "Case 1" Q
t5case3  !, "Case 3" Q
t5case289  !, "Case 2 or 8 or 9" Q
t5case  !,"Case default" Q
}

ClassMethod Run() {
repeat = 1000
ts = $zh for i=1:1:repeat ..Test( $r(10)+1 ) t1 = ( $zh - ts )
ts = $zh for i=1:1:repeat ..Test2( $r(10)+1 ) t2 = ( $zh - ts )
ts = $zh for i=1:1:repeat ..Test3( $r(10)+1 ) t3 = ( $zh - ts )
ts = $zh for i=1:1:repeat ..Test4( $r(10)+1 ) t4 = ( $zh - ts )
ts = $zh for i=1:1:repeat ..Test5( $r(10)+1 ) t5 = ( $zh - ts )
!, "do @( ^||addr() )        : ", t1
!, "do @( addr() )             : ", t2
!, "if val=case Q                : ", t3
!, "do $case( ^||addr() ) : ", t4
!, "do $case( addr() )      : ", t5
}

Output: 

do @( ^||addr() )     : .019535
do @( addr()    )     : .016482
if val=case Q         : .015183
do $case( ^||addr() ) : .015971
do $case( addr() )    : .015078

Open Exchange applications:
Followers:
Following:
Oleg has not followed anybody yet.
Global Masters badges: