How to know when its time to quit grad school, due to my own failings I am in my second semester of a MS in engineering. 

While classwork is fine, research is not going well. I wrote the first few pages of my thesis and basically everything was wrong: formatting, writing style, poor graphs and figures. The results my codes are calculating show that my method makes no improvement to current methodology and sometimes its actually worse. 

My adviser and I keep having miscommunications, and I keep disappointing compared to what I originally showed when we first starting working together. He won't ever tell me directly that I am failing but I can sense his attitude while we talk. 

Due to my job, classes, and thesis work, I have no hobbies and I only sleep every other day.

Is this a normal amount of struggle everyone goes through and I'm overthinking it. Or is this an indication that grad school is not for me?

If I do quit, I will not be able to get a job at a good engineering company due to an average GPA in undergrad.

EDIT: This is an edit for anyone else who might have tendencies to get stress paranoia and start spiraling down negative paths. 

I entirely overestimated the situation, my adviser was perfectly chill about everything, and the issues I thought I was going to get reamed over, were discussed and resolved in about a minute. Instead of criticism, he helped explain a math issue I had, and even let me know some higher-level industry folks he knows were interested in my work.

PSA for people like me (who probably are going to be like me and still worry over everything), making mountains out molehills in your own head is not a wise course of action.
The results my codes are calculating show that my method makes no
  improvement to current methodology and sometimes its actually worse.


For a master's degree, there is usually no requirement that your research produce a successful result. One can make a contribution to science by showing others what doesn't work. But you may find that your new method is an improvement under certain circumstances. Or you may get an idea (after you get some sleep!) for improving your method. That's exactly what happened to me.

Given your lack of sleep and your state of mind, I'm not sure you should trust your impression that your advisor is disappointed in you. I recommend you have a heart-to-heart talk with your advisor, being as open as you can about all your concerns and fears, including that you are stressed out and not sleeping. It's very common for students to feel like failures at some point during a master's degree, and your advisor should be ready to help.


  I wrote the first few pages of my thesis and basically everything was
  wrong: formatting, writing style, poor graphs and figures.


Academic writing is a very different beast than the types of writing you've done before in school. No one is born knowing how to do it. Expect to have to do a lot of rewriting as you learn this skill.