Hi Anton, I modified previous stress test script, see code below. The results ( pentium-III, 800 MHz ): o 1 connected signal => 15 microseconds per call o 10 connected signals => 22 microseconds per call o 100 connected signals => 28 microseconds per call o 1000 connected signals => 100 microseconds per call o 10000 connected signals => 2.7 milliseconds per call Conclusions? Regards. Valeriy ---------------------------- stress.C --------------------------------- #include <TQObject.h> #include <RQ_OBJECT.h> #include <TStopwatch.h> /////////////////////////////////////////////////////////////////////// class A { RQ_OBJECT() private: Int_t fValue; public: A():fValue(0) { } ~A() { } void SetValue(Int_t value); //*SIGNAL* }; //___________________________________________________________________ void A::SetValue(Int_t value) { // Set new value. // Emit signal "SetValue(Int_t)" with a single parameter if(value!=fValue) { fValue=value; Emit(Form("SetValue%d(Int_t)",fValue),fValue); } } ///////////////////////////////////////////////////////////////////// //___________________________________________________________________ void stress() { // Simple tests on signals, slots and connections A a; A b; const Int_t nsignals = 1000; const Int_t nloops = 10; Int_t nevents = 0; for(int i=0; i< nsignals; i++) a.Connect(Form("SetValue%d(Int_t)",i),"A",&b,"SetValue(Int_t)"); TStopwatch timer; timer.Start(); for(int k=0; k<nloops; k++) { for(int i=0; i<nsignals; i++) { a.SetValue(i); nevents++; } } timer.Stop(); printf("Nevents %d, ",nevents); timer.Print(); } ---------------------------- stress.C --------------------------------- Anton Fokin wrote: > Hi Valery, > > thanks for the test. Could you add several extra signals into your test > class to see how list of signals/connections lookup affects the performance? > > Regards, > Anton > > http://www.smartquant.com > > ----- Original Message ----- > From: Valeriy Onuchin <onuchin@fnal.gov> > To: Anton Fokin <anton.fokin@smartquant.com> > Cc: <roottalk@pcroot.cern.ch> > Sent: Monday, March 26, 2001 4:44 AM > Subject: Re: [ROOT] TQObject::Emit() > > > Hi Anton, > > check a simple stress test of signals/slots below. > > - the result on Pentium III 800 Mhz is 15 microseconds per call with > Emit. > > - the result for calls without Emit is 0.015 microseconds per call. > > - the results for compiled executable program are the same. > > > > Regards. Valeriy > > > > > > root [0] .x stress.C++ > > Creating shared library /home/onuchin/tmp/./stress_C.so > > Class A: Streamer() not declared > > Class A: ShowMembers() not declared > > Nevents 1000000, Real time 0:0:14, CP time 14.900 > > > > > > To compile stanalone executable program: > > > > > > $root -b -q >/dev/null stress.C | echo > '{gSystem->CompileMacro("stress.C","kf");}' >tmp.C > > $g++ -o stress stress.C `root-config --cflags --libs` -DSTANDALONE > > > > > > > > > > > > ---------------------------- stress.C --------------------------------- > > > > #include <TQObject.h> > > #include <RQ_OBJECT.h> > > #include <TStopwatch.h> > > > > /////////////////////////////////////////////////////////////////////// > > class A > > { > > RQ_OBJECT() > > > > private: > > Int_t fValue; > > public: > > A():fValue(0) { } > > ~A() { } > > > > void SetValue(Int_t value); file://*SIGNAL* > > }; > > > > > > file://___________________________________________________________________ > > void A::SetValue(Int_t value) > > { > > // Set new value. > > // Emit signal "SetValue(Int_t)" with a single parameter > > > > if(value!=fValue) { > > fValue=value; > > Emit("SetValue(Int_t)",fValue); > > } > > } > > > > ///////////////////////////////////////////////////////////////////// > > file://___________________________________________________________________ > > void stress() > > { > > // Simple tests on signals, slots and connections > > > > A a; > > A b; > > > > a.Connect("SetValue(Int_t)","A",&b,"SetValue(Int_t)"); > > > > const Int_t nevents = 1000000; > > > > TStopwatch timer; > > timer.Start(); > > for(int i=0; i<nevents; i++) a.SetValue(i); > > timer.Stop(); > > printf("Nevents %d, ",nevents); > > timer.Print(); > > } > > > > ///////////////////////////// Main program //////////////////////// > > #ifdef STANDALONE > > > > #include <TROOT.h> > > #include <TApplication.h> > > #include <TSystem.h> > > > > file://---- Main program ------------------------------------------------- > > > > TROOT root("tst","Stress test of signal/slots"); > > > > int main(int argc, char **argv) > > { > > gSystem->Load("./tst_C"); > > TApplication* app = new TApplication("",0,0); > > stress(); > > return 0; > > } > > #endif file://STANDALONE > > > > ---------------------------- stress.C --------------------------------- > > > > > > > > Anton Fokin wrote: > > > > > Hi Valery, > > > > > > I meant that Emit("DataChanged()") call might be time consuming since > you > > > take an argument as char string, compress it and loop over class and > object > > > signal/connection lists (why don't you use hash table, btw?). I was > curious > > > how it is done in Qt/moc. If you say it does nearly the same, no probs. > A > > > benchmark test could be like > > > > > > while (end_test) { > > > DataChanged(); > > > } > > > > > > with and without Emit() in DataChanged(). Of course nobody should be > > > connected to this signal. On the other hand result will depend on how > long > > > are lists of signals... > > > > > > > > I am also not sure what it takes in Qt/moc. In Qt you do not need to > > > call > > > > > Emit() in a signal method - the signal will be emitted automatically > > > once > > > > > the method is declared as signal. > > > > > > > > > > > > > ("It is not correct ..." Valery Fine;) > > > > > > > > > > > > I studied Qt code ... it also uses "Emit" method inside "signal" > > > > Suppose looking at the code produced after MOC preprocessor will > reveal > > > it. > > > > > I am also not sure what it takes in Qt/moc. In Qt you do not need to > > > call > > > > > Emit() in a signal method - the signal will be emitted automatically > > > once > > > > > the method is declared as signal. > > > > > > > > > > > > > ("It is not correct ..." Valery Fine;) > > > > > > > > > > > > I studied Qt code ... it also uses "Emit" method inside "signal" > > > > Suppose looking at the code produced after MOC preprocessor will > reveal > > > it. > > > > > > Yes, that was the questions. I meant that a user does not need to put > Emit() > > > in the body of a signal method in Qt - moc does it. I asked if it is > done in > > > a clever way since moc has control over the code and can make some > "direct" > > > substitutions. > > > > > > Regards, > > > Anton > > > > > > http://www.smartquant.com > > > > > > ----- Original Message ----- > > > From: Valeriy Onuchin <onuchin@fnal.gov> > > > To: Anton Fokin <anton.fokin@smartquant.com> > > > Cc: <roottalk@pcroot.cern.ch> > > > Sent: Thursday, March 22, 2001 11:27 PM > > > Subject: Re: [ROOT] TQObject::Emit() > > > > > > > Hi Anton, > > > > > > > > Anton Fokin wrote: > > > > > > > > > > > > > > > > > > > Hi, > > > > > > > > > > If I want to use singal/slots I have to add Emit("DataChanged()"); > or > > > alike > > > > > in my TQObject inherited class method to emit a signal. I am curious > if > > > this > > > > > call is costly or not. > > > > > > > > What cost do you mean? > > > > > > > > Memory? > > > > > > > > TQObject has 2 data members which are pointers to > > > Lists( sizeof(TList*) = 4 ). > > > > These TLists are created(new TList) only when connection is > > > established > > > > ( sizeof(TList) = 44 ). During creation of connection some > internal > > > structures > > > > are also initiated, but it was designed to make it minimal amd > reuses > > > existent ones. > > > > > > > > > > > > > > > > > > > > > > > I am also not sure what it takes in Qt/moc. In Qt you do not need to > > > call > > > > > Emit() in a signal method - the signal will be emitted automatically > > > once > > > > > the method is declared as signal. > > > > > > > > > > > > > ("It is not correct ..." Valery Fine;) > > > > > > > > > > > > I studied Qt code ... it also uses "Emit" method inside "signal" > > > > Suppose looking at the code produced after MOC preprocessor will > reveal > > > it. > > > > > > > > > > > > > > > > > > > > > > So could you comment on performance of Emit("DataCahnged()") > decoding > > > (with > > > > > CINT dict, etc.) compare to Qt moc processing. > > > > > > > > Fair comparison of benchmark tests is always difficult task > > > > ( btw it's not a bad business > > > http://www.tpc.org/information/about/join.asp ) > > > > > > > > Suggest the "fair test" and I/we can try it. > > > > > > > > > > > > Regards. Valeriy > > > > > > > > > > > > > > > > > >
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:40 MET