There's a formula for this, kinda! To determine if voting is worth it.
pB + D > C
Where p = the probability of your vote being the deciding ballot, B = the utility derived from your candidate winning, D = any social or psychological benefit you derive from voting, and C = the cost of voting.
p is almost always some very small, non-zero number, so pB is effectively zero. Basically comes down to your sense of civic duty outweighing the costs of voting.
I knew taking social choice theory would come in handy one day. Thanks, Heckelman.
I still vote religiously.