Loading ...
Sorry, an error occurred while loading the content.

[Clip] Benchmarking NoteTab Functions

Expand Messages
  • RS
    Hi All, A few days ago, on occasion of a commentary regarding the use of ^!IfTrue and ^!If, I posted a Clip to test the performance of those instructions.
    Message 1 of 1 , Aug 26, 1999
    View Source
    • 0 Attachment
      Hi All,

      A few days ago, on occasion of a commentary regarding the use of ^!IfTrue
      and ^!If, I posted a Clip to test the performance of those instructions.
      Those who read it will remember they were actually two Clips, one for each

      At the time, I didn't consider going through the trouble of displaying the
      elapsed time, and was content with just showing the Starting and Ending
      time. Displaying the time isn't as simple as subtracting both time values,
      because they are in Hours, Minutes and Seconds, and there is no function to
      do that in NoteTab. Though I had an old routine I wrote some time ago, that
      routine was in Visual Basic and required to be converted to NoteTab, an
      always difficult operation. Worst of all, I had misplaced the function and
      wasn't able to find it.

      Since there was a discussion going on these days on the List about
      converting Degrees to Decimal, my interest was revived and decided, this
      time with more luck, to look for the lost routine. Should I have been
      wiser, I wouldn't have! It took me quite a few hours, plus a mild headache,
      to have it adapted and working on NoteTab. If you've programmed for a
      while, you must be familiar with those things that look sooo easy you can
      have them running in a few minutes, but turn out taking far more time and
      effort than initially planned.

      Well, the routine is done, it works, and you and I can now use it in other
      Clips. It hopefully will help other NoteTabers that may need it. It can
      also be "easily" converted to other environments.

      Furthermore, it allows me now, to add "that little improvement that means
      everything" to the benchmark Clip I mentioned above, which is the reason of
      this post.

      The Clip will allow you to test one or more NoteTab instructions at a time
      to measure their performance.

      It might be of interest to other NoteTab programmers in that it shows how
      you can implement subroutines inside the same Clip, without the need to use
      external support Clips. The DMS and InvDMS external Clips I posted
      elsewhere appear here integrated within the main Clip (under the "subDMS"
      and "subInvDMS" labels), and the code demonstrates the use of a simple, but
      effective, technique to access those subroutines. (NoteTab does not support
      user functions nor subroutines at this time, but it allows us to do some
      tricks impossible on other environments!)

      ;======== Start ========
      ; RS - 08/26/99 6:44:12 PM, based on:
      ; RS - 08/19/99 7:07:51 PM
      ; Edited with ClipWriter 1.0
      ; http://home.att.net/~ptools/ClipWriter/cw.htm
      ; http://home.att.net/~ptools/main/index.htm

      ;Change the Seed value to increase
      ;or decrease the number of loop
      ;iterations and time for the test.
      ;Notice that the total number of
      ;iterations is always equal (Seed + 1).
      ;So, if you want to have 1000 iterations
      ;exactly, Seed should be 999.

      ;This example is meant just to test
      ;the ^!IfTrue statement. To test other
      ;instructions, just place them before
      ;the ^!IfTrue line after the ":loop" label.

      ^!Set Seed=1000
      ^!Set iters=^%Seed%
      ^!Inc iters
      ^!Set Seed=-^%Seed%

      ^!Set StartTime=^$GetDate(hh:mm:ss)$
      ^!SetScreenUpdate OFF
      ^!Inc Seed
      ^!IfTrue ^%Seed% Msg
      ^!Goto loop

      ^!Set EndTime=^$GetDate(hh:mm:ss)$

      ;Calculate elapsed time:

      ^!Set ret=Ret2
      ^!Set DMS=^%EndTime%
      ^!Goto subDMS
      ^!Set t2= ^%DMS%

      ;@ Bookmark 1

      ^!Set ret=Ret1
      ^!Set DMS=^%StartTime%
      ^!Goto subDMS
      ^!Set t1= ^%DMS%

      ;calculate & convert to HH:MM:SS:
      ^!Set ret=Ret0
      ^!Set InvDMS=^$Calc(^%t2% - ^%t1%;4)$
      ^!Goto subInvDMS

      ^!SetScreenUpdate ON
      ^!SetWizardTitle Benchmark
      ^!Info BENCHMARK RESULTS ^p^p for ^%iters% loop iterations ^p^p Start =
      ^%StartTime% ^p End = ^%EndTime% ^p^p Elapsed Time = ^%InvDMS%

      ^!ClearVariable DMS
      ^!ClearVariable EndTime
      ^!ClearVariable InvDMS
      ^!ClearVariable Ret
      ^!ClearVariable Seed
      ^!ClearVariable StartTime
      ^!ClearVariable t1
      ^!ClearVariable t2

      ^!Goto End

      ; Subroutines/Functions:

      ; DMS function
      ;Converts value in DMS (Degrees-Minutes-Seconds)
      ;to Decimal value.

      ^!Set h=^%DMS%

      ^!Set i=^$StrPos(":";^%h%;True)$
      ^!Set m=0
      ^!Set s=0
      ^!If ^%i% = 0 convert

      ^!Set m=^$StrDelete(^%h%;1;^%i%)$
      ^!Dec i
      ^!Set h=^$StrCopy(^%h%;1;^%i%)$

      ^!Set i=^$StrPos(":";^%m%;True)$
      ^!If ^%i% = 0 convert
      ^!Inc i
      ^!Set s=^$StrCopy(^%m%;^%i;40)$
      ^!Dec i 2
      ^!Set m=^$StrCopy(^%m%;1;^%i%)$

      ^!Set DMS=^$Calc((^%h% * 3600 + ^%m% * 60 + ^%s%)/3600;4)$

      ^!ClearVariable h
      ^!ClearVariable m
      ^!ClearVariable s
      ^!ClearVariable i

      ^!Goto ^%ret%



      ; InvDMS function
      ;Converts decimal value to DMS

      ^!Set n=^%InvDMS%

      ^!Set i=^$StrPos(".";^%n%;True)$
      ^!Dec i
      ^!Set h=^$StrCopy(^%n%;1;^%i%)$

      ^!Set x=^$StrDelete(^%n%;1;^%i%)$
      ^!Set x=^$Calc(^%x% * 60;4)$

      ^!Set i=^$StrPos(".";^%x%;True)$
      ^!Dec i
      ^!Set m=^$StrCopy(^%x%;1;^%i%)$

      ^!Set s=0
      ^!If ^%i% = 0 Next1
      ^!Set x=^$StrDelete(^%x%;1;^%i%)$
      ^!Set s=^$Calc((^%x% * 60) + .5;2)$
      ;just 2 digits:
      ^!Set i=^$StrPos(".";^%s%;True)$
      ^!Dec i
      ^!Set s=^$StrCopy(^%s%;1;^%i%)$

      ^!If ^%m% > 9 skip
      ^!Set m=0^%m%
      ^!If ^%s% > 9 Next2
      ^!Set s=0^%s%

      ^!Set InvDMS=^%h%:^%m%:^%s%

      ^!ClearVariable h
      ^!ClearVariable i
      ^!ClearVariable m
      ^!ClearVariable n
      ^!ClearVariable s
      ^!ClearVariable x

      ^!Goto ^%ret%
      ;========= End =========


    Your message has been successfully submitted and would be delivered to recipients shortly.