Length of ROOT.std.vector

Hi experts, I have a some code which plays with TTrees with std::vector branches, and a common operation is finding the length of such a vector. Is it more efficient to use the python built-in len() function, or the v.size() method of the vector?

I did try to write a simple script with cProfile to see the difference, but I got inconclusive results: 0.001 vs 0.002 seconds for getting the length of a bunch of huge vectors. In the end I think I might have been profiling python’s ability to loop over a list of vectors instead of the actual len() vs .size()…

Jean-François

Hi,

just off the top of my head: why don’t you use “time” to check the time it takes your program to run. If your only change is len() <-> .size(), the differences in the runtimes should give you the answer.

Cheers,
e_dude

Hi,

a call of len() in python means calling the method len. For std::vector, len is size (that is, the reference in the dict of the class that is labeled as len actually points to size; as does the label size, of course), so there can be no difference.

Cheers,
Wim