Alan Schoenfeld has written a fair amount about mathematical problem solving; you may be interested in some of his work. This particular question falls under the category of what he would call "control decisions." The question should not only be how much time you spend on a math problem, but also how much time you spend on a particular approach as you try to solve said problem.
Schoenfeld also writes about beliefs, and how many students think that math problems should be solved quickly or not at all. This is (as you might well guess) a belief that associates negatively with mathematical problem solving performance.
My advice to you is to try different strategies when you are stagnating. George Polya has a long list of strategies ("heuristics") for problem solving, including: try a special case; try a simpler problem; try a similar problem; generalize; draw a picture. For every question that you cannot solve, there is a slightly easier question that you can't solve either! Mess around with things until you gain some traction and have a better sense of how to broach the problem at hand.
With regard to time spent: don't let your grades suffer too much, since this will probably lead to undesirable consequences down the road. The amount of time I spend on a problem depends on why I'm trying to solve it. If it's just for fun, then I work on it when I have free time; often you need a period of incubation (a break from work) before you can have a major insight. If it's a problem set for a class or perhaps a take-home test, then you probably should spend more time on it (though breaks are still necessary!).
Persistence and curiosity are important characteristics for any math student or mathematician, but don't lose focus and let your course grade suffer too much as a result. (And as for your classmates who are seemingly solving things much more quickly: pay them no mind.)