It's always worthwhile to take some time to try to figure it out by yourself. But eventually there's a point where you're unsure how much more time it would take to figure it out by yourself (which could take far longer than you originally think), and when asking for help could be more helpful.
So for analytical or computational research, what are some guidelines for when you should ask for help (from either your adviser, other grad students, or other researchers) when you get stuck?
It took me six months to gather the courage to talk to my research adviser when I was stuck on a project that I knew would "never" work. I should not have waited so long. The conversation we had was very helpful, got me back on track, and, more importantly, got me off the project.
If you are in the same place for more than two or three weeks, its time to have a frank discussion with your research adviser. It's unlikely that he or she knows that you are stuck. The best case scenario is that you have a plan to get unstuck. The worst case scenario is that you are no better off. If you already have a committee, then your next step is to go to the other committee members for help.