Time diagnostics

Hello,

Does anyone know if Grasshopper allows us to time the execution of a code to see how long it takes to fully solve a solution (in milliseconds)? Grossly simplified, this is what I need:

Best Regards,
Sofia

Hi,

NO

Or

Are you looking for this ?

Profiler Widget

The profiler lists worst-case runtimes for parameters and components, allowing you to track performance.

Source

Cheers,
BVR

You might be able to adapt this? Two copies, read the time before and after, then calc the difference?

Here’s a Python thing; every time you push the button (or otherwise trigger the ‘x’ input?), the date/time updates:

import datetime
now = datetime.datetime.now()
Y = now.year
M = now.month
D = now.day
h = now.hour
m = now.minute
s = now.second


time_date_2019Jul8a.gh (5.5 KB)

Thanks for your reply. No, that’s not what I’m looking for. I wanted to time the performance of a large chunk of connected components and see how long it takes to solve it from beginning to end. I guess, I could sum the individual performances of each relevant component but I was wondering if there was a better way to do that.

Stick it in a cluster and then use the profiler?

This simple test depends on a single final result to trigger the second timer. Nothing happens immediately when the ‘Count’ slider is changed but at the end, it shows two timestamps that differ by approximately the same interval as shown by the Profiler. Computing the difference between two timestamps (elapsed time) is more than I care to do for fun today.


elapsed_2020Sep6a.gh (12.3 KB)

Thank you for your code, Joseph. That works for longer times but in my case I wanted more precision (ms).

Stick it in a cluster and then use the profiler?

Grouping everything in a cluster and using a profiler to measure performance seems to do the trick for what I needed. Thanks everyone for your replies!

Python has a vast array of time/date methods that include milliseconds, microseconds and ‘timedelta’:

https://docs.python.org/3/library/datetime.html

I added a milliseconds output (‘ms’) but unfortunately, I’m neither familiar enough with Python nor patient enough today to figure out elapsed time.


elapsed_2020Sep6b.gh (14.4 KB)

1 Like

I’ve spent more time on this than I care to admit… I can get the Python datetime code to work fine, as expected. But try as I may, getting an elapsed time has failed a dozen different ways! How absurd that something so simple and routine in every language I’ve ever used is so difficult with Grasshopper. :man_facepalming:

1 Like