Michael Nielsen did an analysis on this based on his own usage. He found that the time he spent reviewing a card over a lifetime is about 10 minutes (i.e. he'd spend 10 minutes of his life reviewing the card over and over before it's memorized "for good"). So his calculus was:
"In the future, of all the times I will need this information, will I spend more than 10 minutes looking it up?"
If the answer is no, he won't bother creating flashcards.
If the answer is yes, he will.
Now that doesn't account for the time spent creating the card, but for most cards it will definitely take under a minute to create - so it doesn't change things much.
Writing cards vs doing exercises is comparing very different concerns. One needs to eat as well, but it wouldn't make sense to ask "Write cards vs eating."
Flashcards are for recall. Exercises are for understanding. It is true if you use a concept over and over in practice exercises, it will aid in recall as well. But for concepts you use less often (i.e. fewer exercises), you are more likely to forget them. Flashcards guard against that.
Case in point: I took tons of engineering and physics courses. So the usual undergraduate calculus, along with trigonometric identities, are ingrained in my mind even though I haven't used them in over a decade. Now consider complex analysis (or complex calculus). It was one of my favorite math classes. But I rarely applied that knowledge in other courses. As a result, despite the fact that I basically reviewed the material twice after taking the course, I still remember almost none of it.
I could force myself to do complex analysis exercises occasionally for the rest of my life. Or I could put them in flashcards. The former will definitely lead to a richer, deeper understanding, but is impractical due to the heavy time requirements. The latter is a good compromise.
I avoid thinking about the opportunity cost and predicting what to learn for maximum efficiency – that could drive anyone crazy!
I mainly follow my emotions and varying interests and try to convince myself that most of what I learn can be very useful, it just rests on me to find ways to use it. It helps that I'm a big fan of applying wisdom from different disciplines to find unexpected solutions to problems.
I do however focus a lot on fundamental insights, the things that actually help me guide a web search in the first place. If I didn't have rooted deeply in my brain that the sample error is composed of bias, between-unit variance, and sample size, I wouldn't even know to start looking for ways to reduce between-unit variance as an economical alternative to increasing sample size.