I’m a physics student new to ROOT, and actually to C/C++ interpreters.
I am trying to understand the “ROOT language”, my question is "How slow is ROOT compared to
the traditional Compiled C++. So i made this code to compare:
using namespace std;
clock_t tStart = clock()
double sum = 0;
sum += pow(j,3);
cout << double(clock() - tStart) / (double)CLOCKS_PER_SEC;
The problem is i’m getting Errors, how to solve this ?
Error: Symbol CLOCKS_PER_SEC is not defined in current scope test.cpp:15:
Error: Symbol inf is not defined in current scope test.cpp:15:
PS: i’m not discussing all facilities ROOT may provide, just execution time, kind of realize when use ROOT, when not.
I guess you are not showing the correct code because you should be getting a different error message: it should be something like
error: expected ‘,’ or ‘;’ before ‘double’ because a semicolon is missing after the call to
clock(). After fixing that, your program compiles/runs in root.
Also, be very careful when testing. Variables or even whole calculations might get optimized away if you dont use the result. Often is is very useful to look at the assembly output that is generated. At https://gcc.godbolt.org/ you can paste your code and test different compilers and settings.
In “interpreted code”, ROOT 5.x does not know about “CLOCKS_PER_SEC” (but ROOT 6.x does), so you need to “precompile” it with ACLiC, using something like “root  .x test.cxx++”.
And even more to watch out for: please test using ROOT 6. It has a completely new C++ interpreter; the previous one has been retired. You would see that ROOT 6 is much faster then ROOT 5. (Wile’s suggestion of using
.x test.cxx++ doesn’t actually test much of the interpreter - it compiles the code into a shared library and calls into that. For ROOT 6 you don’t need to do that; a simple
.x test.cxx will do.)
Even for ROOT 6, if you want to compare the speed of compiled versus interpreted code: please use the current master (check https://root.cern.ch/building-root ) because I have enabled optimizations in the interpreter only a few days ago. That, too, will make a dramatic difference…
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.