Re: Time of TNode->Clone()

Rene Brun (Rene.Brun@cern.ch)
Fri, 20 Feb 1998 12:20:24 +0100


Alexander Zvyagin wrote:
>
> IHEP, Protvino, Russia, 18-FEB-1998
>
> Dear all!
>
> I have next macro:
>
> // File b.C
> void b(UInt_t N)
> {
> if( N==0 ) N=1;
>
> gROOT->Reset();
> g1 = new TGeometry ("Tempory","Tempory geometry");
>
> new TBRIK("MAIN","This is main frame","void",10,10,10);
> main_node = new TNode("MAINnode","This is main node","MAIN");
> main_node->BuildListOfNodes();
> main_node->cd();
>
> new TBRIK("A","A","void",1,1,1);
> Anode = new TNode("Anode","Anode","A");
>
> TStopwatch timer;
> timer.Start();
>
> for( int i=0; i<N; i++ )
> {
> TNode *node = (TNode*) Anode->Clone();
> if( NULL==node )
> {
> printf("Can not create node.\n");
> exit(1);
> }
> main_node->GetListOfNodes()->Add(node);
> }
>
> timer.Stop();
> printf("N=%d rate = %g seconds per node\n",N,timer.CpuTime()/N);
>
> return;
> }
>
> ROOT session:
>
> *******************************************
> * *
> * W E L C O M E to R O O T *
> * *
> * Version 1.03/09 16 December 1997 *
> * *
> * You are welcome to visit our Web site *
> * http://root.cern.ch *
> * *
> *******************************************
>
> CINT/ROOT C/C++ Interpreter version 5.13.36, Nov 30 1997
> Type ? for help. Commands must be C++ statements.
> Enclose multiple statements between { }.
> root [0] .x b.C(7);
> N=7 rate = 0.0128571 seconds per node
> NULL
> root [1] .x b.C(8);
> N=8 rate = 0.025 seconds per node
> NULL
> root [2] .x b.C(9);
> N=9 rate = 0.0555556 seconds per node
> NULL
> root [3] .x b.C(10);
> N=10 rate = 0.148 seconds per node
> NULL
> root [4] .x b.C(11);
> N=11 rate = 0.541818 seconds per node
> NULL
> root [5] .x b.C(12);
> N=12 rate = 2.43833 seconds per node
> NULL
> root [6] .x b.C(13);
> N=13 rate = 10.64 seconds per node
> NULL
>
> The time of TNode::Clone() + TNode::GetListOfNodes()->Add() depends strongly
> from nodes amount.
> Why?

Alexander,
Be careful when using the Clone function !
In the case of a TNode object, this object references material,
a shape, the parent node and sons. If you clone this object,
(TNode::Clone) is using TNone::Streamer), you get a copy of all
objects referenced by this node. This is an exponential behaviour.

I have modified your macro to do what (I think) you want to do.
You can create many thousand nodes per second.

Rene Brun

// File nodes.C
void nodes(UInt_t N)
{
if( N==0 ) N=1;

// gROOT->Reset();
g1 = new TGeometry ("Tempory","Tempory geometry");

brik = new TBRIK("MAIN","This is main frame","void",10,10,10);
main_node = new TNode("MAINnode","This is main node","MAIN");
main_node->cd();

brik = new TBRIK("A","A","void",1,1,1);
char node_name[30];
char node_title[30];

TStopwatch timer;
timer.Start();

for( int i=0; i<N; i++ )
{
sprintf(node_name,"node%d",i);
sprintf(node_title,"node number %d",i);
TNode *node = new TNode(node_name,node_title,"A");
if( NULL==node )
{
printf("Can not create node.\n");
exit(1);
}
}

timer.Stop();
printf("N=%d rate = %g seconds per node\n",N,timer.CpuTime()/N);

return;
}