Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

timing!!

Status
Not open for further replies.

sergelaurent

Technical User
May 30, 2005
52
FR
Hi everybody!!!

I want to measure the time taken to execute a command!! I wanted to know if there was a special command to do this?

The method which seems best to me is to take the system's time before and after executing the command!!! However, i have another problem!!! Is there a command to take the system's time at a particular moment!!

Thanks in advance,
Laurent
 
There is a command to time a script:
time script ?count?
This command will call the Tcl interpreter count times to evaluate script (or once if count isn't specified). It will then return a string of the form

503 microseconds per iteration

which indicates the average amount of time required per iteration, in microseconds. Time is measured in elapsed time, not CPU time.

Your second question may now be moot, but the command to get the current time is:
clock seconds
Return the current date and time as a system-dependent integer value. The unit of the value is seconds, allowing it to be used for relative time calculations. The value is usually defined as total elapsed time from an ``epoch''. You shouldn't assume the value of the epoch.

The output of clock seconds can be formatted with clock format (no surprise there).



_________________
Bob Rashkin
 
Thanks!!!

However, i don't want to take the time to execute a script but the time to execute one of the commands in the script!!!!

is there another solution apart from taking the time before and after the command!!!
 
Hi

And what ? In Tcl 1 script = 1 or more commands = 1 string.
Code:
puts "Enter a number :"
gets stdin c

puts "Wait while I count to $c..."
set t [time {for {set i 0} {$i<$c} {incr i} { } }]
puts "Done"

puts "I counted to $c in $t microseconds."
( Could you please use correct punctuation at the end of your senteces ? )

Feherke.
 
Hi

Oops. Actually this is the one I want to post :
Code:
puts "Enter a number :"
gets stdin c

puts "Wait while I count to $c..."
set t [red][lindex[/red] [time {for {set i 0} {$i<$c} {incr i} { } }] [red]0][/red]
puts "Done"

puts "I counted to $c in $t microseconds."

Feherke.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top