ScriptSpot

Forum topic · General Scripting

loop execution time

By tinnnpo · 2012-02-22

Description

Hi!
is there a way to get elapsed time during a loop execution? for exemple showing the elapsed time in label.text (second by second)

Comments (4)

tinnnpo · 2012-02-23

thank you all for yours inputs I didn't know timeStamp() function however what I wanted to do is real time chronometre but it seems impossible since even max render counter is not live :)

elapsed time + time left?

Anubis · 2012-02-24

As I remember how Max measure elapsed time and time left for rendering statistic, in scripting it may look something like:

beginTime = timeStamp()
for t = 10 to 60 do
(
	strTime = timeStamp()
	render frame:t vfb:off
	endTime = timeStamp()
	
	endFrmTime = endTime - strTime
	elapsedTime = endTime - beginTime
	timeLeft = (60 - t + 1) * endFrmTime
	
	format "Elapsed Time: %\n" elapsedTime
	format "Time Left: %\n" timeLeft
)

In other words (a bit fake) the calculation of the time left is based on the last elapsed time. Not perfect but better than nothing.

miauu · 2012-02-22

Use the progressbar control. I think that you can't calculate how long will take the loop execution. You can use counter and can show in label "processed/total count".

(
	cnt = 0
	for i = 1 to selection.count do
	(
		cnt += 1
		format "Processed % of % \n " cnt selection.count 
	)
)

You can use timeStamp() to

br0t · 2012-02-22

You can use


timeStamp()

to get the milliseconds since midnight I think, or use


localTime

to get date and time as a string. Do this at the start and end of your loop and calculate the difference (With

localTime

you'll have to do some string formatting, e.g. with

substring

and with

timeStamp()

you'd have to convert it to seconds, minutes etc. by division)
Cheers