Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5963087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:11:53+00:00 2026-05-22T19:11:53+00:00

I need the time in milliseconds for what could be a large volume of

  • 0

I need the time in milliseconds for what could be a large volume of transactions, so I want something that is correct, and fast. Will the following work and do the job best? :


    iMilli  := int((time.Nanoseconds() % 1e6) / 1e3)

TIA

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T19:11:53+00:00Added an answer on May 22, 2026 at 7:11 pm

    EDIT: Since this answer was first written, escape analysis code has been added to the Go compilers. This allows the compiler to avoid unnecessary allocations in certain situations, including (probably) the one described below. With the latest weeklies, therefore, it may be just as good to use a more straightforward call to time.Nanoseconds(). Please do your own profiling.

    Most of the time functions cause a heap allocation (that then subsequently needs to be collected, causing a pause in your application). So if you’re looking up the time frequently, which it sounds like you are, you’ll need to use syscall.Gettimeofday() directly (it’s the function that the other time functions end up calling anyway). See the discussion here for more information:

    http://groups.google.com/group/golang-nuts/browse_thread/thread/f2209022f43efcca?pli=1

    The solution I’m using is to pre-allocate a tv syscall.Timeval, and each time through my inner loop I do this:

    syscall.Gettimeofday(&tv)
    

    You can then get the milliseconds with:

    (int64(tv.Sec)*1e3 + int64(tv.Usec)/1e3)
    

    I’ve found this to perform a lot better than calling time.Nanoseconds() or one of the other higher-level time functions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a high precision time method in microseconds rather than milliseconds for actionscript,
Every time I need to work with date and/or timstamps in Java I always
Every time I need to do something N times inside an algorithm using C#
I need to get execution time in milliseconds. Note : I originally asked this
I need a very accurate way to time parts of my program. I could
I have time in milliseconds for ex. 1308700800000 ; I need to convert it
I need to capture the amount of time that ASP.net takes to execute each
I need to store the execution time (in milliseconds) of a function in a
I have some functions that I am calling and they take some time (milliseconds),
I have this time in milliseconds that i am receiving in an XML feed,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.