//+______________________________________________________________________________ // Performance test of all the ROOT random generator (TRandom, TRandom1, TRandom2 and TRandom3) // Tests the generator TRandom3 against some ref values // and creates a timing table against TRandom, TRandom1 and TRandom2. // // E.g. on an an Intel Xeon Quad-core Harpertown (E5410) 2.33 GHz running // Linux SLC4 64 bit and compiled with gcc 3.4 // // Distribution nanoseconds/call // TRandom TRandom1 TRandom2 TRandom3 // Rndm.............. 5.000 105.000 7.000 10.000 // RndmArray......... 4.000 104.000 6.000 9.000 // Gaus.............. 36.000 180.000 40.000 48.000 // Rannor............ 118.000 220.000 120.000 124.000 // Landau............ 22.000 123.000 26.000 31.000 // Exponential....... 93.000 198.000 98.000 104.000 // Binomial(5,0.5)... 30.000 548.000 46.000 65.000 // Binomial(15,0.5).. 75.000 1615.000 125.000 178.000 // Poisson(3)........ 96.000 494.000 109.000 125.000 // Poisson(10)....... 138.000 1236.000 165.000 203.000 // Poisson(70)....... 818.000 1195.000 835.000 844.000 // Poisson(100)...... 837.000 1218.000 849.000 864.000 // GausTF1........... 83.000 180.000 87.000 88.000 // LandauTF1......... 80.000 180.000 83.000 86.000 // GausUNURAN........ 40.000 139.000 41.000 44.000 // PoissonUNURAN(10). 85.000 271.000 92.000 102.000 // PoissonUNURAN(100) 62.000 256.000 69.000 78.000 // // // Note that this tutorial can be executed in interpreted or compiled mode // Root > .x testrandom.C // Root > .x testrandom.C++ // //Authors: Rene Brun, Lorenzo Moneta #include #include #include #include #include #include #include #include void testAll() { int i, N = 5000000; float cpn = 1000000000./N; double x,y; TRandom *rsave = gRandom; TRandom *r0 = new TRandom(); TRandom *r1 = new TRandom1(); TRandom *r2 = new TRandom2(); TRandom *r3 = new TRandom3(); TStopwatch sw; printf("Distribution nanoseconds/call\n"); printf(" TRandom TRandom1 TRandom2 TRandom3\n"); sw.Start(); for (i=0;iRndm(i); } printf("Rndm.............. %8.3f",sw.CpuTime()*cpn); sw.Start(); for (i=0;iRndm(i); } printf(" %8.3f",sw.CpuTime()*cpn); sw.Start(); for (i=0;iRndm(i); } printf(" %8.3f",sw.CpuTime()*cpn); sw.Start(); for (i=0;iRndm(i); } printf(" %8.3f\n",sw.CpuTime()*cpn); const int NR = 1000; double rn[NR]; sw.Start(); for (i=0;iRndmArray(NR,rn); } printf("RndmArray......... %8.3f",sw.CpuTime()*cpn); sw.Start(); for (i=0;iRndmArray(NR,rn); } printf(" %8.3f",sw.CpuTime()*cpn); sw.Start(); for (i=0;iRndmArray(NR,rn); } printf(" %8.3f",sw.CpuTime()*cpn); sw.Start(); for (i=0;iRndmArray(NR,rn); } printf(" %8.3f\n",sw.CpuTime()*cpn); sw.Start(); for (i=0;iGaus(0,1); } printf("Gaus.............. %8.3f",sw.CpuTime()*cpn); sw.Start(); for (i=0;iGaus(0,1); } printf(" %8.3f",sw.CpuTime()*cpn); sw.Start(); for (i=0;iGaus(0,1); } printf(" %8.3f",sw.CpuTime()*cpn); sw.Start(); for (i=0;iGaus(0,1); } printf(" %8.3f\n",sw.CpuTime()*cpn); sw.Start(); for (i=0;iRannor(x,y); } printf("Rannor............ %8.3f",sw.CpuTime()*cpn); sw.Start(); for (i=0;iRannor(x,y); } printf(" %8.3f",sw.CpuTime()*cpn); sw.Start(); for (i=0;iRannor(x,y); } printf(" %8.3f",sw.CpuTime()*cpn); sw.Start(); for (i=0;iRannor(x,y); } printf(" %8.3f\n",sw.CpuTime()*cpn); sw.Start(); for (i=0;iLandau(0,1); } printf("Landau............ %8.3f",sw.CpuTime()*cpn); sw.Start(); for (i=0;iLandau(0,1); } printf(" %8.3f",sw.CpuTime()*cpn); sw.Start(); for (i=0;iLandau(0,1); } printf(" %8.3f",sw.CpuTime()*cpn); sw.Start(); for (i=0;iLandau(0,1); } printf(" %8.3f\n",sw.CpuTime()*cpn); sw.Start(); for (i=0;iExp(1); } printf("Exponential....... %8.3f",sw.CpuTime()*cpn); sw.Start(); for (i=0;iExp(1); } printf(" %8.3f",sw.CpuTime()*cpn); sw.Start(); for (i=0;iExp(1); } printf(" %8.3f",sw.CpuTime()*cpn); sw.Start(); for (i=0;iExp(1); } printf(" %8.3f\n",sw.CpuTime()*cpn); sw.Start(); for (i=0;iBinomial(5,0.5); } printf("Binomial(5,0.5)... %8.3f",sw.CpuTime()*cpn); sw.Start(); for (i=0;iBinomial(5,0.5); } printf(" %8.3f",sw.CpuTime()*cpn); sw.Start(); for (i=0;iBinomial(5,0.5); } printf(" %8.3f",sw.CpuTime()*cpn); sw.Start(); for (i=0;iBinomial(5,0.5); } printf(" %8.3f\n",sw.CpuTime()*cpn); sw.Start(); for (i=0;iBinomial(15,0.5); } printf("Binomial(15,0.5).. %8.3f",sw.CpuTime()*cpn); sw.Start(); for (i=0;iBinomial(15,0.5); } printf(" %8.3f",sw.CpuTime()*cpn); sw.Start(); for (i=0;iBinomial(15,0.5); } printf(" %8.3f",sw.CpuTime()*cpn); sw.Start(); for (i=0;iBinomial(15,0.5); } printf(" %8.3f\n",sw.CpuTime()*cpn); sw.Start(); for (i=0;iPoisson(3); } printf("Poisson(3)........ %8.3f",sw.CpuTime()*cpn); sw.Start(); for (i=0;iPoisson(3); } printf(" %8.3f",sw.CpuTime()*cpn); sw.Start(); for (i=0;iPoisson(3); } printf(" %8.3f",sw.CpuTime()*cpn); sw.Start(); for (i=0;iPoisson(3); } printf(" %8.3f\n",sw.CpuTime()*cpn); sw.Start(); for (i=0;iPoisson(10); } printf("Poisson(10)....... %8.3f",sw.CpuTime()*cpn); sw.Start(); for (i=0;iPoisson(10); } printf(" %8.3f",sw.CpuTime()*cpn); sw.Start(); for (i=0;iPoisson(10); } printf(" %8.3f",sw.CpuTime()*cpn); sw.Start(); for (i=0;iPoisson(10); } printf(" %8.3f\n",sw.CpuTime()*cpn); sw.Start(); for (i=0;iPoisson(70); } printf("Poisson(70)....... %8.3f",sw.CpuTime()*cpn); sw.Start(); for (i=0;iPoisson(70); } printf(" %8.3f",sw.CpuTime()*cpn); sw.Start(); for (i=0;iPoisson(70); } printf(" %8.3f",sw.CpuTime()*cpn); sw.Start(); for (i=0;iPoisson(70); } printf(" %8.3f\n",sw.CpuTime()*cpn); sw.Start(); for (i=0;iPoisson(100); } printf("Poisson(100)...... %8.3f",sw.CpuTime()*cpn); sw.Start(); for (i=0;iPoisson(100); } printf(" %8.3f",sw.CpuTime()*cpn); sw.Start(); for (i=0;iPoisson(100); } printf(" %8.3f",sw.CpuTime()*cpn); sw.Start(); for (i=0;iPoisson(100); } printf(" %8.3f\n",sw.CpuTime()*cpn); TF1 *f1 = new TF1("f1","gaus",-4,4); f1->SetParameters(1,0,1); gRandom = r0; sw.Start(); for (i=0;iGetRandom(); } printf("GausTF1........... %8.3f",sw.CpuTime()*cpn); gRandom = r1; sw.Start(); for (i=0;iGetRandom(); } printf(" %8.3f",sw.CpuTime()*cpn); gRandom = r2; sw.Start(); for (i=0;iGetRandom(); } printf(" %8.3f",sw.CpuTime()*cpn); gRandom = r3; sw.Start(); for (i=0;iGetRandom(); } printf(" %8.3f\n",sw.CpuTime()*cpn); TF1 *f2 = new TF1("f2","landau",-5,15); f2->SetParameters(1,0,1); gRandom = r0; sw.Start(); for (i=0;iGetRandom(); } printf("LandauTF1......... %8.3f",sw.CpuTime()*cpn); gRandom = r1; sw.Start(); for (i=0;iGetRandom(); } printf(" %8.3f",sw.CpuTime()*cpn); gRandom = r2; sw.Start(); for (i=0;iGetRandom(); } printf(" %8.3f",sw.CpuTime()*cpn); gRandom = r3; sw.Start(); for (i=0;iGetRandom(); } printf(" %8.3f\n",sw.CpuTime()*cpn); // test using Unuran TUnuran unr0(r0); TUnuran unr1(r1); TUnuran unr2(r2); TUnuran unr3(r3); // continuous distribution (ex. Gaus) TUnuranContDist dist(f1); // use arou method (is probably the fastest) unr0.Init(dist,"arou"); unr1.Init(dist,"arou"); unr2.Init(dist,"arou"); unr3.Init(dist,"arou"); sw.Start(); for (i=0;i 10e-8) { printf("i=%d x=%.8f but should be %.8f\n",i,x,RefValue[i]); rc1 += 1; } } // check whether a state can be saved and restored TFile *file = new TFile("random3.root","RECREATE"); file->SetCompressionLevel(0); r.Write("r"); delete file; file = new TFile("random3.root"); TRandom3 *rs = (TRandom3*) file->Get("r"); for (i=0;i<1000;i++) { if (r.Rndm() - rs->Rndm() != 0) rc2 += 1; } if (rc2 != 0) printf("state restoration failed\n"); return rc1 + rc2; } void testrandom() { testRandom3(); testAll(); }