Announcement

Collapse
No announcement yet.

Time that has one-millisecond resolution using console compiler.

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Time that has one-millisecond resolution using console compiler.

    Are there any examples of using the console compiler to get one-millisecond resolution for time stamps on data file records?

  • #2
    You must use a windows API
    search for code using the key word "dirslist".
    I think files are dated to Greenwich time internally.
    p purvis

    Comment


    • #3
      In PBCC 6 see PowerTime in Help. (The same thing in PBWin 10 is iPowerTime). PowerTime is very compatable with API FileTime UDT (user defined type (or called structure on MSDN).

      I recommend keeping the time stamps as PowerTime objects/FileTime types, as UTC (Coordinated Universal Time (French influence turns letters around)). Only takes 8 bytes to store, and you can do comparisions and arithmatic easily. With Powertime methods, or conversion of FileTime to SystemTime UDT, you get years, months, days, hours, minutes, seconds and milliSeconds no problem. As local time too!

      With older versions of PB you have to use FileTime, SystemTime, and API functions/subs. Luckily they are easy to use.

      I'll assume you'll be back with more specific questions.

      In addition to PB Help, seach on google for "msdn filetime" (without the quotes).

      Cheers,
      Dale

      Comment


      • #4
        Paul addressed that you wanted time(s) of file. It is in UTC in FileTime UDT variable. Also see DIR$ with TO option in PB Help.(plus or minus a leap second or two GMT = UTC)

        I answered toward putting a time stamp field in the records in the file.

        Cheers again,
        Dale

        Comment


        • #5
          Vince. Yes I did oversee the issue you were asking for.
          For whatever reason. I missed reading the word "records" and was thinking or reading time stamps on data files. Even when we think times stamps in data records, there are usually important reasons to have them some time in the future. Keep up the good practice.
          p purvis

          Comment


          • #6
            This may also be of interest. Added a couple of lines since code displayed using PBWin..
            https://msdn.microsoft.com/library/w...sktop/ms644904
            Code:
            'https://forum.powerbasic.com/forum/user-to-user-discussions/source-code/24907-accurate-time-interval-measurement?t=24258
            'by Erik Christensen   May 2004
            #COMPILE EXE
            '#REGISTER NONE
            #DIM ALL
            '
            #INCLUDE "win32api.inc"
            '
            FUNCTION CurrentTimePointInSeconds AS DOUBLE
                ' This function returns the number of seconds since midnight
                ' as a Double-precision floating-point value.
                STATIC PerfFreq AS QUAD, RES AS LONG, Prec AS LONG, First AS LONG, TimeCorrection AS DOUBLE
                LOCAL t1 AS QUAD, ta AS DOUBLE
                '
                IF ISFALSE First THEN
                    'This code only runs once if RES is set
                    ' Get, in counts per second, the current performance-counter frequency
                    ' if supported by your hardware.
                    RES = QueryPerformanceFrequency(PerfFreq)
                    '
                    ' Determine Precision
                    IF RES THEN
                        Prec = CEIL(LOG10(PerfFreq))
                        QueryPerformanceCounter t1
                        ta = ROUND(CDBL(t1) / CDBL(PerfFreq), Prec)
                        ' Find time correction to obtain number of seconds past midnight.
                        TimeCorrection = TIMER - ta
                        '
                        FUNCTION = ta + TimeCorrection
                        First = %TRUE
                        EXIT FUNCTION
                    ELSE
                        Prec = 2 ' Precision of TIMER is only about 1/18th of a second.
                    END IF
                    First = %TRUE
                END IF
                ' Measure current time
                IF RES THEN ' if possible use this:
                    QueryPerformanceCounter t1
                    FUNCTION = ROUND(CDBL(t1) / CDBL(PerfFreq), Prec) + TimeCorrection
                ELSE        ' else use the built-in timer
                    ta = TIMER
                    FUNCTION = ROUND(ta, Prec)
                END IF
                '
            END FUNCTION
            '
            FUNCTION PBMAIN AS LONG
                LOCAL t1 AS DOUBLE, t2 AS DOUBLE
                LOCAL tx AS STRING
                '
                ' Measure first time
                t1 = CurrentTimePointInSeconds
                '
                SLEEP 550 ' sleep 0.55 seconds
                '
                ' Measure second time
                t2 = CurrentTimePointInSeconds
            
                #IF NOT %DEF(%PB_CC32)
                 tx = "Time 1: " + FORMAT$(t1) + " seconds past midnight" + $CRLF
                 tx = tx + "Time 2: " + FORMAT$(t2) + " seconds past midnight" + $CRLF + $CRLF
                 tx = tx + "Time interval in seconds is: " + FORMAT$(t2 - t1, "######.#########")
                 MSGBOX tx, %MB_ICONINFORMATION, "Maximum accuracy time interval measurement"
                #ELSE
                 PRINT "Time 1: " + FORMAT$(t1) + " seconds past midnight"
                 PRINT "Time 2: " + FORMAT$(t2) + " seconds past midnight"
                 PRINT
                 PRINT
                 PRINT "Time interval in seconds is: " + FORMAT$(t2 - t1, "######.#########")
                 PRINT "Press a key to exit";WAITKEY$
                #ENDIF
            END FUNCTION
            https://www.tesla.com/roadster

            Comment


            • #7
              The same question was asked 51 minutes earlier in the 'timeBeginPeriod update' thread in the Programming Forum. An answer was posted 150 minutes later.

              The question there was: "Do you guys have experience adding time stamps to data that have 1 milliseconds resolution using the console compiler?" which is less ambiguous than the question here.

              Comment


              • #8
                Originally posted by David Roberts View Post
                The same question was asked 51 minutes earlier in the 'timeBeginPeriod update' thread in the Programming Forum. An answer was posted 150 minutes later.

                The question there was: "Do you guys have experience adding time stamps to data that have 1 milliseconds resolution using the console compiler?" which is less ambiguous than the question here.
                mmmm? "less ambiguous" - is that better or worse then "more unique" or "slightly pregnant"?
                [I]I made a coding error once - but fortunately I fixed it before anyone noticed[/I]
                Kerry Farmer

                Comment


                • #9
                  Ambiguity is a variable not a constant.

                  "susceptible of two or more interpretations"

                  So, two interpretations are less ambiguous than three interpretations and so on.

                  Comment


                  • #10
                    Originally posted by David Roberts View Post
                    Ambiguity is a variable not a constant.

                    "susceptible of two or more interpretations"

                    So, two interpretations are less ambiguous than three interpretations and so on.
                    oh dear

                    We shall have to agree to disagree on this matter!
                    [I]I made a coding error once - but fortunately I fixed it before anyone noticed[/I]
                    Kerry Farmer

                    Comment


                    • #11
                      Originally posted by Kerry Farmer
                      We shall have to agree to disagree on this matter!
                      Roll up, roll up - two mathematicians in disagreement.

                      I was thinking, Kerry, that you may have ambiguity on your mind. With only one interpretation we have no ambiguity. With two interpretations we have ambiguity. With three interpretations we have ambiguity, and so on. However, I used the word ambiguous and not ambiguity; that is the degree of ambiguity or level of ambiguity.

                      Anyway, not to worry.

                      Comment


                      • #12
                        Originally posted by Kerry Farmer View Post
                        We shall have to agree to disagree on this matter!
                        I think we all know what the issue is here. It's 'fewer' ambiguity innit, not 'less'

                        Comment


                        • #13
                          Originally posted by Bob Carver View Post

                          I think we all know what the issue is here. It's 'fewer' ambiguity innit, not 'less'
                          Nope it's fewer ambiguities

                          Comment

                          Working...
                          X