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

  • SEARCH
  • Home
  • 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 8653747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:37:01+00:00 2026-06-12T14:37:01+00:00

For a framework I’m writing I would like to measure how much a piece

  • 0

For a framework I’m writing I would like to measure how much a piece of (bash) code takes to execute and then print the elapsed time in seconds.

For measuring, I do the following:

start=$(date +%s%N)

# do something here

elapsed_time=$(($(date +%s%N) - start))

This gives me the elapsed seconds concatenated with the elapsed nanos. If I now divide this by 1000000, I’ll get the time in ms

elapsed_time_in_ms=$(($elapsed time / 1000000))

This is all nice and seems to work but the real problem is that I want to print it in this format:

12.789s

where before the . are the seconds and after the dot are last 3 digits of the ms value.

How would I achieve something like that?

EDIT

I am aware that the time would probably not of much use, still I would like to implement this (even if only for cosmetic reasons :-)).

EDIT 2

For anyone facing the same problem:

In the end I’ve chosen to use time as it doesn’t require a fork and seems to be the most portable solution.

Have a look at the it function and the global total_elapsed_time variable here to see how I implemented this.

  • 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-06-12T14:37:02+00:00Added an answer on June 12, 2026 at 2:37 pm

    You can use bc command:

    elapsed_time_in_ms=$(echo "scale=3;$elapsed_time/1000000" | bc)
    

    The scale basically sets the number of digits you want after the .

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

Sidebar

Related Questions

My framework is raising a syntax error when I try to execute this code:
Zend framework is well known for loosely coupled components. I would like to use
Akka framework recommends using typed actor only for interacting with external code. However, standard
Our framework requires wrapping certain functions in some ugly boilerplate code: def prefix_myname_suffix(obj): def
which framework helps in reducing the number of lines of code needed to create
.framework bundles contain header files which are also included when then framework is shipped.
Entity Framework Code First will auto-create a table in the database base based on
Zend Framework 1.11.11 I am writing a Zend Framework Controller Plugin that does stuff
Entity Framework Code First is a great framework for developing new projects. But what
Framework: I'm using using MVC 3 + EntityFramework 4.1 Code-First. Concept: One Legislation entity

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.