timing a simulation

timing a simulation

Anonymous
Not applicable
1,865 Views
4 Replies
Message 1 of 5

timing a simulation

Anonymous
Not applicable

I'm working on a couple scripts that will be used to benchmark various hardware, but I'm struggling with timing a simulation. Basically I want to start a simulation and see how long it takes to perform 50 or 100 frames. Any suggestions? I assuming some sort of callback, or using IsSolverRunning() but have come up empty. 

0 Likes
Accepted solutions (1)
1,866 Views
4 Replies
Replies (4)
Message 2 of 5

ads_royje
Alumni
Alumni

Hi @Anonymous ,

 

I hope I get the question correctly.
You are trying to measure time a simulation takes to run using maxscript ?

If so.
Maxscript will wait for the simulation to end before continuing to next line, using timestamp() should give you the start and end time of the simulation.

start_time = timestamp()
-- run simulation code
end_time = timestamp()
total_time = (end_time - start_time) 
format "Simulation took % milliseconds.\n" total_time
format "Simulation took % seconds.\n" (total_time / 1000.0 )

If that does not work as you expect, what Simulation is being ran in Max ?

Regards,

0 Likes
Message 3 of 5

Anonymous
Not applicable

I tried doing:

startTime = timeStamp()
solver.runsolve()
endTime = timeStamp()

 

but that just returns:

44010860
true
44011095
235
Simulation took 235 milliseconds.
OK
Simulation took 0.235 seconds.
OK
OK

that doesn't seem like it is waiting for the end before moving to the next line. The simulation runs for about a full minute

0 Likes
Message 4 of 5

ads_royje
Alumni
Alumni
Accepted solution

Hi @Anonymous !

Ha, I see, you are using Fluids! 🙂

That is a different system indeed.

 

As you were suspecting, you are right. You need to use IsSolverRunning() to pause the script while Fluids is calculating the solve.


The easiest approach is the use: while (isSolverRunning) do ()
Given a Fluid object named "Liquid001" with 1 solver

start_time = timestamp()
$Liquid001.solvers[1].runSolve()
while ($Liquid001.solvers[1].IsSolveRunning()) do
(
-- while Fluids is running, do nothing, so script waits for the end of Fluid's calculation before going any further
)

end_time = timestamp()
total_time = (end_time - start_time) 
format "Simulation took % milliseconds.\n" total_time
format "Simulation took % seconds.\n" (total_time / 1000.0 )


Let me know if that works for you or not,
Regards,

0 Likes
Message 5 of 5

Anonymous
Not applicable

That works perfectly. Thank you! Its interesting that its different. I'm developing a benchmark suit for Max to test hardware performance, so I'll have to dig into this a bit more. I'm sure I'll be back with plenty more questions.