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 8830579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:07:36+00:00 2026-06-14T08:07:36+00:00

In Java program, I usually use the following functions to profile time info: …

  • 0

In Java program, I usually use the following functions to profile time info:

...
long start = System.currentTimeMillis();
...
...
System.out.println("elapsed time 1: "+(System.currentTimeMills() - start));
...
...
start = System.currentTimeMillis();
...
System.out.println("elapsed time 2: "+(System.currentTimeMills() - start));
...

How to do similar things in shell bash? Further, how to collect the accumulated time if there is a loop?

e.g.

for ((i=0;i<$lines;i=i+$step))
do    
    head -$((i+step)) $1 | tail -$step > tmp1
    head -$((i+step)) $2 | tail -$step > tmp2
    setstr=$setstr' '`./accuracy.sh tmp1 tmp2`
done
echo $setstr | awk '{for (i=1;i<=NF;i++) sum+=$i; }END{print sum/NF}'

I want to profile the accumulated head/tail time and accuracy.sh tmp1 tmp2 time separately.

  • 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-14T08:07:37+00:00Added an answer on June 14, 2026 at 8:07 am

    You can prefix the command you wish to time with the appropriately named time command.

    For example:

    time find . -type f -name hello_world.cc
    

    Or in your case:

    time head -$((i+step)) $1 | tail -$step > tmp1
    time head -$((i+step)) $2 | tail -$step > tmp2
    time setstr=$setstr' '`./accuracy.sh tmp1 tmp2`
    

    Note that time outputs to tty, so you don’t have to worry about the results of timing being written to tmp1 or tmp2 etc.

    If you’d like to watch the total elapsed time (since the script has started running) update in real time, you can do this:

    At the start of your script, take note of the system time:

    start_timestamp=$(date +%s)
    

    Then start your actual script main:

    # Do your execution here
    

    Then within your loops, wherever you’d like to see output of elapsed time so far

    curr_timestamp=$(date +%s)
    elapsed_time=$(expr $end_time - $start_time)
    echo "Elapsed: $elapsed_time" >> elapsed_time.log
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

when i am loading some data into my java program, i usually use FileInputStream.
Usually i start debug a java program by type jdb in terminal, then it
Ok so I've just started learning java (I usually program in Objective-C). My first
I'm calling a java program from my python code in the following way: subprocess.check_output([java,
Usually a java program is running with a single process called javaw.And when I
I'm a relative newbie to Java. I program in other languages and I use
I am developing a program in Java that I will use for registering data.
I usually run this program via a command line like so: java Program <TestClass.java
I usually use the Hibernate ThreadLocal session management pattern in Java web projects: The
I have written a java program generates lots of files (say txt files) in

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.