Dead simple Clarion Stopwatch Class

Something I needed today but didn’t have.

Based on the .NET Stopwatch Class but only using the precision of Clarion Clock() and Today()

Implemented:

  • Start
  • StartNew
  • Stop
  • Reset
  • Restart
  • Elapsed
  • ToString
  PROGRAM
  Include('Stopwatch.inc'),ONCE
  MAP
  END

SW Stopwatch
    CODE

    SW.Start()

    ! Do some things that take time...
    ! Perhaps Thread.Sleep(10000)

    SW.Stop()

    Message('Elapsed Ticks: ' & SW.Elapsed())
    Message('Time Elapsed: ' & SW.ToString())  ! e.g. 2 days, 00:12:54

https://github.com/fushnisoft/ClarionClasses/blob/master/Src/Stopwatch.inc

https://github.com/fushnisoft/ClarionClasses/blob/master/Src/Stopwatch.clw

3 Likes

I was thinking about this just recently and procrastinating on creating it myself. Thanks! This will save me a bunch of time.

1 Like

Note: If you’re less squeamish about using includes, and composing classes from other classes

You might want to take a peek at my ctTimedResultsClass

It uses ctDateTimeLong which can be found in this folder:

1 Like

:smiley:

But yes, do check out the work from Mark! In this case I just wanted something very self contained.
The IFDEF technique around the EQUATES would be a good safeguard which I failed to include in my original above.

   OMIT('*** IFDEF ***', TIME:Second)
TIME:Tick   EQUATE(  1)
TIME:Second EQUATE(100 * TIME:Tick)
TIME:Minute EQUATE( 60 * TIME:Second)
TIME:Hour   EQUATE( 60 * TIME:Minute)
TIME:Day    EQUATE( 24 * TIME:Hour  )
 !END-OMIT('*** IFDEF ***', TIME:Second)

I was just reading a blog over at hanselman land, Proper benchmarking to diagnose and solve a .NET serialization bottleneck, where he mentions the .NET Stopwatch class and linked to the source code.

Used this class today. :slight_smile:

6 Likes

I’ve often thought time would be easier if it was decimal with an hour divided into 100 minutes.

I recently saw a presentation on time which noted that 60 was used for dividing minutes and seconds because 60 is divisible by 10 factors 2, 3, 4, 5, 6, 10, 12, 15, 20, 30 making it easy to split an hour fractionally 10 ways into even minutes. Also nice it is divisible by numbers 1 to 6.

Base 60 has a name Sexagesimal that sounds a bit naughty. Maybe a good name for rapper or supermodel.

3 Likes