Both are them are quite different batsmen blessed with different capabilities. Babar is mainstay of batting in all three formats of the game for Pakistan and is pretty conventional type of batsman. Babar's case is completely different from that of Rahul, Pak's batting atm is completely dependent on how Babar performs, no one in Pakistani setup comes even close to him. While for Rahul, it's pretty relaxed atmosphere in a way because of India's top 3, who more often than not get the job done esp in the LOIs, where he is slowly settling as lower middle order bastman at #5.
Coming to the comparison point, only format where we can somehow make a case for comparison is in T20Is, both open the innings(although it's unclear where Rahul is gonna bat once both Dhawan and Rohit are back in T20Is) and imo Rahul is ahead of Babar in that format mostly bcz of his power game. But again it's about the roles, Rahul's role is to provide a solid start or rather a quick one and in Babar's case, he has to make sure he stays till the end, it needs to be understood that both have very contrasting roles, if you put Rahul in Babar's place or vice versa, I am sure both are gonna fail or at least not perform at the level they are doing right now.
Coming to ODIs, overall I think it's too early to compare Rahul with Babar, imo Babar wins the battle based on stats but they don't always tell the whole picture. Rahul is yet to cement his place in the ODI setup, that could be because of the standard of the batting India has, he could be easily replaced by anyone else if he puts up a string of low scores. Having said that, he still has got a lot of chances, he's already played 30+ ODIs and hasn't been able to fulfill his potential yet, although it looks like he might be settling at #5 position, so would be interesting to see if he can keep the scores coming. Babar at #3 and Rahul at #5 in ODIs can't be compared at all, it's injustice with either of them.
In Test format, a year back I would have said that both are kinda equal with Rahul slightly ahead because of his overseas performance, but Babar has been a beast in last year or so in Test cricket getting better and better with every ball he faces, another thing that goes in Babar's favour is that he used to usually bat at #5 or #6 in Test up until Aus series, it was only during that tour that he made #4 his permanent position, while in Rahul's case he regularly used to bat in the top order. In Test cricket, i would say Babar is way ahead of Rahul atm and it's gonna take something tremendous from Rahul to match Babar in Tests.
So in short(although I have written a pretty long thesis) I feel both can't be compared and put head to head with each other(esp in LOIs) because of all the reasons I have mentioned.
But if we are to compare both the players across all the formats irrespective of where they bat, how they bat, which team they are playing for, etc, then imo it would go like this:
T20Is - Rahul
ODIs - Babar
Tests - Babar
Overall - Babar