31 std::cout <<
"Testing size n = " << n <<
"\t(Time / call in microsec.) " << std::endl;
36 for (
Int_t i = 0; i <
n; i++) {
40 std::sort(k.begin(), k.end());
46 for (
int j = 0; j <
npass; ++j) {
47 for (
T elem = 0; elem <
maxint; ++elem ) {
54 cout <<
"TMath::BinarySearch time :\t " << *tTMath << endl;
59 for (
int j = 0; j <
npass; ++j) {
60 for (
T elem = 0; elem <
maxint; ++elem ) {
62 pind = std::lower_bound(&k[0], &k[n], elem);
63 Long_t index2 = ((*pind == elem)? (pind - &k[0]): ( pind - &k[0] - 1));
68 *tStd = t.
RealTime()/double(npass)*1.E6;
69 std::cout <<
"std::binary_search time:\t " << *tStd <<
'\n' << std::endl;
72 Error(
"testBinarySearch",
"Different results obtained for size n = %d - s1 = %d s2 = %d",n,s1,s2);
91 ok &= testBinarySearch<Double_t>(i, &tM[j], &tS[j]);
99 cout <<
" TMATH - time --- std time " << std::endl;
100 for ( i = 0; i < ntest; ++i) {
101 cout <<
" size = " << index[i] <<
" : " << tM[i] <<
' ' << tS[i] << endl;
114 gM->
SetTitle(
"TMath::BinarySearch()");
121 gS->
SetTitle(
"std::binary_search()");
125 legend->
AddEntry(gM,
"TMath::BinarySearch()");
126 legend->
AddEntry(gS,
"std::binary_search()");
129 gM->
SetTitle(
"Comparision of Searching Time");
138 cout <<
"Test done!" << endl;
140 cout <<
"Error: Test Failed!" << endl;
144 int main(
int argc,
char **argv)
148 for (
Int_t i=1 ; i<argc ; i++) {
149 std::string arg = argv[i] ;
158 cerr <<
"Usage: " << argv[0] <<
" [-g] [-v]\n";
160 cerr <<
" -g : graphics mode\n";
161 cerr <<
" -v : verbose mode";
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Double_t RealTime()
Stop the stopwatch (if it is running) and return the realtime (in seconds) passed between the start a...
This class displays a legend box (TPaveText) containing several legend entries.
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
Random number generator class based on the maximally quidistributed combined Tausworthe generator by ...
virtual void Draw(Option_t *option="")
Draw this legend with its current attributes.
TAxis * GetYaxis() const
Get y axis of the graph.
virtual void SetTitle(const char *title="")
Set graph title.
int main(int argc, char **argv)
virtual void Draw(Option_t *chopt="")
Draw this graph with its current attributes.
void Stop()
Stop the stopwatch.
virtual void Run(Bool_t retrn=kFALSE)
Main application eventloop. Calls system dependent eventloop via gSystem.
virtual UInt_t Integer(UInt_t imax)
Returns a random integer on [ 0, imax-1 ].
bool testBinarySearch(const int n, double *tTMath, double *tStd)
virtual void SetLogx(Int_t value=1)
Set Lin/Log scale for X.
void Error(const char *location, const char *msgfmt,...)
virtual void SetLineColor(Color_t lcolor)
Set the line color.
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
TAxis * GetXaxis() const
Get x axis of the graph.
TLegendEntry * AddEntry(const TObject *obj, const char *label="", Option_t *option="lpf")
Add a new entry to this legend.
A Graph is a graphics object made of two arrays X and Y with npoints each.
This class creates the ROOT Application Environment that interfaces to the windowing system eventloop...
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Long64_t BinarySearch(Long64_t n, const T *array, T value)