Saving a canvas in a file is so slow

Hi,

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

Hi,

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>
#endif

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

  g.Draw("AP");
  wall.Start();
  gPad->SaveAs("test2.gif");
  std::cout << wall.RealTime() << std::endl;
}

#ifndef __CINT__
int main() {
  test();
}
#endif

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:
g->SetMarkerStyle(20);
saving the plot as a GIFF file takes much much longer. Is there a fundamental reason for this behavior?
Thank you,

Florent

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