Learn how to use Dash Bio for next-gen sequencing & quality control. 🧬 Register for the Oct 27 webinar.

Measure the speed of an output

Hi everyone,

I’m trying to find a way to measure the time that my app takes to give me the results I ask (plot figures, tables and text). Is there any way to to this?
For the moment I just use the python’s time module in every callback that I have (see example bellow), but the result doesn’t seem to correspond to the actual time that it takes because it doesn’t take into consideration the plotting part…

    [Input('some_value', 'children')],
    [State('other_value', 'value')])
def total_chiffres(val, choix):
    deb = time()
   #some code
   fig = px.pie(values =values, names=some_name, color_discrete_sequence=px.colors.diverging.PuOr)
   print('Running this callback took :', time()-deb)
   return fig


I found two easy ways:

  1. Providing a custom DashRenderer, example:
app.renderer = '''
var t0 = 0;
var renderer = new DashRenderer({
    request_pre: (payload) => {
        t0 = performance.now();
    request_post: (payload, response) => {
        const t1 = performance.now();
        console.log("Took " + (t1 - t0) / 1000 + " sec (" + payload.output + ")");

Then you can just filter your browser console by “Took” and you will only see the elapsed time.

  1. Use your profiler in the browser, for example in Chrome, there is Performance tab in the Developer Console, which you can use to measure exactly how long the _dash-update-component took.

Nice trick @Higgcz!

One day jjaraalm will wrap up this PR and we’ll have this type of performance metrics available by default :slight_smile: