ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
In lots of different languages, you can do a kind of stop watch around a function or group of lines to see how long it/they takes.
Can you do something like that in tcsh? I need to be able to time in at least tenths of a second & preferably hundredths. What I'm trying to do is something like this:
Code:
#!/bin/tcsh -f
`do_some_stuff`
start = date
foreach f in (`foo`)
do_something
end
end = date
elapsed = end - start
echo "It took $elapsed seconds"
Is something like this possible?
I don't want to "time" the whole script because I want to time several parts of the script to see where the slowness is.
nanosecond resolution for timing is completely worthless. Variation due to scheduling overhead is far less precise, on the order of tenths of seconds. Use the "time" command.
nanosecond resolution for timing is completely worthless. Variation due to scheduling overhead is far less precise, on the order of tenths of seconds. Use the "time" command.
I don't think you can use time from within a script, though, can you? IN other words, can I run time around 3 loops within a script to see how long each loop takes?
time If set to a number, then the time builtin (q.v.) executes auto-
matically after each command which takes more than that many
CPU seconds.
-- excerpt from man tcsh
For example, using a local program burn to use an approximate amount of CPU time:
Code:
#!/usr/bin/env tcsh
# @(#) s1 Demonstrate tcsh automatic timing of simple commands.
echo
setenv LC_ALL C ; setenv LANG C
echo "Environment: LC_ALL = $LC_ALL, LANG = $LANG"
echo "(Versions displayed with local utility version)"
sh -c "version >/dev/null 2>&1" && version "=o" tcsh
echo
set time = 1
echo " Time set to $time"
echo " Burning for 2"
burn 2
echo
echo " Time for burn of 3"
burn 3
echo
exit 0
producing:
Code:
% ./s1
Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility version)
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution : Debian GNU/Linux 5.0
tcsh 6.14.00
Time set to 1
Burning for 2
calibration end = 0.22, start = 0
Iterations = 50000, time = 0.22 seconds.
Iterations = 404545.454545455, time = 1.84 seconds.
2.060u 0.008s 0:02.13 96.7% 0+0k 0+0io 0pf+0w
Time for burn of 3
calibration end = 0.22, start = 0
Iterations = 50000, time = 0.22 seconds.
Iterations = 631818.181818182, time = 2.88 seconds.
3.104u 0.004s 0:03.82 81.1% 0+0k 0+0io 0pf+0w
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.