Caffeine and modafinil shouldn’t be compared, as they have vastly different activity, history of use, and understanding of effects.
This is merely an anecdote, but I was prescribed modafinil for narcoleptic symptoms. Compared to traditional psychostimulants, I found it to be ineffective with a more severe side effect profile. Of course, YMMV.