Uploaded image for project: 'Erlang/OTP'
  1. Erlang/OTP
  2. ERL-608

Better time handling (grabbing native time unit/ timer.tc variant/alternative)

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Help Wanted
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      (first thanks for Erlang et. al. <3)

      I have a suggestion for making time measurements better/more accurate. The normal built-in way to measure function execution time is timer.tc/n but as described in its documentation and implemented it always returns.

      However, for instance on my Linux system the time measuring according to `erts_internal:time_unit/0` is nano seconds so precision is given up.

      One could just reimplement timer.tc but without knowing what time unit monotonic_time returns it's hard as usage of erts_internal functions is clearly discouraged. Making the "native" time unit part of the public API would probably be the easiest fix.

      (There are workarounds like converting the monotonic time returned to another unit until you figure out the unit where it doesn't change).

      Another idea would to offer an alternative to timer.tc that doesn't only return the time but the (native) unit it was measured in as well. So instead of

      {1000, result}

      the return value might be {{1000, microscond}, result}.

      That'd be great and I think would help people who want to casually measure execution times (for logging purposes) or do more advanced things with them.

      (I maintain a benchmarking library on the BEAM and stumbled across this as the native unit on Windows seems to be milliseconds which was a surprise to us)

      Sorry if I didn't fill out some fields I should have.

        Attachments

          Activity

            People

            Assignee:
            otp_team_vm Team VM
            Reporter:
            PragTob Tobias Pfeiffer
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated: