Saving a canvas in a file is so slow


I have a compiled code which saves a plotted TGraph (“g”) in a GIF file. It looks like this:

TCanvas *Wcan = new TCanvas("WcanTP","WcanTP",0,0,750,500); Wcan->Draw(); TPad *Wpad = new TPad("WpadTP","WpadTP",0,0,1,1); Wpad->Draw(); Wpad->cd(); g->Draw("AP"); Wcan->SaveAs("./mygraph.gif")

The graph “g” is pretty big: ~1,000,000 points. It takes a long time (more than one minute) to perform the “SaveAs()” function.

What I don’t understand is that it takes about 1 second when I perform the same list of commands interactively with ROOT. I’d like to have a compiled code which runs just as fast. What should I do?

Thank you


are you sure the time is spent saving the file? This seems to take the same amount of time in interpreted, compiled with ACLiC and with a proper compiler for me with root-5.34.03. This was my test code:

#ifndef __CINT__
#include <iostream>
#include <TPad.h>
#include <TGraph.h>
#include <TRandom.h>
#include <TStopwatch.h>

void test() {
  TStopwatch wall;
  TGraph g(10000000);
  for (int i=0; i<10000000; ++i)
    g.SetPoint(i, gRandom->Rndm(), gRandom->Rndm());

  std::cout << wall.RealTime() << std::endl;

#ifndef __CINT__
int main() {

Hi Honk,

Sorry, it took me some time to come back to this post. I used your code and indeed I don’t see any difference between the interpreter and the compiled code.

However I identified the reason why my code is so slow. If you add the following style command:
saving the plot as a GIFF file takes much much longer. Is there a fundamental reason for this behavior?
Thank you,


Yes, this markers are much more complex to draw that simple dots.