How does TGraph::Eval() find interpolation points and how fast is it?

Let’s say I have 2 arrays (set of coordinates):


If I want to know some y(x) I can just calculate the linear interpolation between some points of the array. x is the position of moving particle, so it increases with time. I can keep track of the lower and upper values of x[] for the linear interpolation, and find y(x) easily. However, it’s just tedious to have those lines of code in my script checking lower and upper values all the time.

I thought of doing this defining a TGraph object with x[] and y[], so I can just use TGraph::Eval(x). I’d like to know how this function finds the lower and upper values for x and if this significantly slower for large N

See the reference guide for TGraph::Eval()
You can even look at the code.