I want to know how much wall-time it takes to display a Graphics

For example this one:

ballGrid[n_] := Module[{lines},
  lines = Line[Flatten[Table[{
       {{i, j, 0}, {i, j, 1}},
       {{i, 0, j}, {i, 1, j}},
       {{0, i, j}, {1, i, j}}},
      {i, 0, 1, 1/n}, {j, 0, 1, 1/n}], 2]];
  Graphics3D[{Sphere[Tuples[Range[0, 1, 1/n], 3], 1/(10 n)], lines}, 
   Boxed -> False]]

First of all note that running ballGrid[50] and ballGrid[50]; takes significantly different wall time to run

Just using AbsoluteTiming does not give accurate representation (I assume it only measures kernel time):

In[]:= AbsoluteTiming[ballGrid[50];]
In[]:= AbsoluteTiming[ballGrid[50]]
Out[]:= {0.082963,Null}
Out[]:= {0.029378,<<Graphics>>}

I answered my own question, but I'd like to see other solutions too, and know why/if the Print workaround can be trusted


3 Answers 3


From past experimentation (not all of which I remember) here are several things that contribute to the time it takes to display graphics, including:

  • converting the Graphics expression to boxes (in the kernel)

  • compressing the result if it's very large (if you examine large graphics cells, you'll notice that they're compressed)

  • transferring the (possibly compressed) box expression to the Front End through MathLink

  • rendering the graphics

I played with these a little bit in the past, trying to figure out what contributes the most to the timing. Unfortunately I don't remember all the details (and I won't have time to do all the tests again now), but I do know that: 1. converting to boxes might take longer than the rendering itself in some cases 2. compression may take measurable time too.

If you want to measure the full time needed to display a Graphics, then I recommend something like

s = AbsoluteTime[];


AbsoluteTime[] - s

In order or this to give correct results, each command must be in a separate cell.

This gives me 4.9 seconds, which is about the same time I measure with my watch.

The following should be a good approximation to the total display time too, but it'll usually take a little longer to evaluate (5.1 seconds here):

ExportString[ballGrid[30], "BMP"]; // AbsoluteTiming

This will measure box generation only (1.2 seconds):


You can add compression on top of that (1.8 seconds), AbsoluteTiming[Compress@ToBoxes[ballGrid[30]];], but I'm not sure that the same compression method implemented in Compress is used when sending the data to the FE.

Your method (AbsoluteTiming[Print@ballGrid[30]]) should include at least box generation and compression, and possibly MathLink transfer too (just a guess, I'm not sure about this last one). It gives 2.0 seconds on my machine, but I can measure 5 seconds with a watch before I actually see the graphics.

I hope this answer will help you in digging deeper into what happens exactly when graphics are displayed and how to time the process correctly ... I simply wanted to point out that doing this is not quite as straightforward as it might seem at first.


I typically execute t=AbsoluteTime[] immediately before execution of the graphics command (in the same cell, even) and then execute AbsoluteTime[]-t in the cell immediately after. It's important that you select and enter both Input cells simultaneously - as the cells are selected in the image below.

enter image description here

  • $\begingroup$ That gave me 2s extra compared to the Print workaround, and that agrees with true time. How come they have to be on different input cells? Does that force Mathematica to render the output before giving the next input to the kernel? $\endgroup$
    – ssch
    Commented Nov 15, 2012 at 16:58
  • $\begingroup$ @ssch I believe that's essentially correct. Rendering is done in the front end. Once a Graphics expression is sent to the front end, the kernel can get to work on input in the current cell, but not the next cell. $\endgroup$ Commented Nov 15, 2012 at 17:13

One workaround is to use Print

In[]:= AbsoluteTiming[Print[ballGrid[50]];]
Out[]:= {14.438180, Null}
  • 1
    $\begingroup$ I think this will time formatting the graphics expression (converting to boxes), but it will not time rendering. Depending on what sort of graphics you are displaying, both operations might take a significant time. $\endgroup$
    – Szabolcs
    Commented Nov 15, 2012 at 16:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.