I suspect that this is the type of question that can only be answered by experience, so I will attempt to do so.
In my experience, it entirely depends (sorry, I know this is likely not the clear yes/no answer you are looking for). For the below, however, I will be making some assumptions:
- You are only being hit by a single red or blue shell.
- Lakitu recovery times are consistent (I'm not sure if this is actually the case in the game, but I must assume so for the purposes of answering this question effectively).
Having attempted to test this out myself, I have come to the following conclusions:
- It is faster to take the hit if you are being hit by a red shell. There are 2 reasons for this - first, trying to use Lakitu to your advantage when falling off the course is generally very risky. While sometimes he will drop you off close to where you fell off, I have found that more often, Lakitu will return you to the track slightly further back than where you fell off. Given that the other racers are still going while you are being returned, I have found it very difficult to try and recover my place when relying on Lakitu. Second, the red shell recovery is shorter than that of the blue shell, and I find that sometimes I can try to preserve at least some of the forward momentum from being hit by a red shell (not the case with a blue shell).
- It is generally faster to take the hit from the blue shell. This, as above, is mainly due to the unpredictability of Lakitu. If Lakitu is dropping you off further back from where you were, or even returning you to the exact same spot you fell off, I have found that taking the blue shell hit is usually faster. Although the explosion from the shell takes time, my trial and error testing tells me that this explosion is still shorter than fa,lling off the track. However, there are some situations in which Lakitu may be faster...
- Lakitu may be faster if he returns you further than where you fell off AND if you were going to be hit by a blue shell. As you noted in your question, and as I can confirm in my experience, Lakitu will sometimes return you further up the track than where you fell off. This, combined with the fact that blue shells take longer to recover from than red shells, means that occasionally driving off the stage can be a more effective route to saving time. HOWEVER, in my testing this was only the case when Lakitu returns you sufficiently further up the track, AND you avoided being hit by a blue shell. Although it depends where you fell off, in my experience Lakitu probably returned me further up the track only 10-20% of the time, and even then it was not significantly further than where I fell off. Combined with needing to know it is a blue shell before you drive off (since if it were red the recovery time is too short to warrant driving off), I found this strategy very difficult to pull off, though admittedly with enough practice it could become feasible.
tl;dr: It is sometimes faster to drive off if you are avoiding a blue shell and Lakitu returns you further up the track, though this strategy is extremely risky and unpredictable, so I would probably just take the hit.