Thread: Program is slow. Help

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    50

    Program is slow. Help

    My program is almost done but it is very slow. I wrote it in C++ . I am new at this and this is the biggest program I've ever written. I probably wrote some things the long way. I heard that writing code in assembly language speeds a program up tremendously. Is this true? Would it be as simple as disassembling my program and then compiling it with the assembly code ? I'm just looking for a simple method right now rather than digging into my code. Also, I didn't use any classes since I'm not good with them yet. I also didn't use very many functions. Would using either one of these speed it up? I need to cut some major time off of my program.

    Also, my program is currently doing 1.19 x 10^56 loops. As I write more code that will increase and it is already too slow. I have a 2 ghz computer with 630 mb ram.

    Actually, this is my first real C++ program so go easy on me.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > I heard that writing code in assembly language speeds a program up tremendously. Is this true?
    Only in exceptional circumstances.

    The real gains come from a better understanding of the problem and choosing better algorithms. For example, no body uses bubble sort for sorting millons of records, they use instead quicksort.

    The real problem is the number of loops you have
    "Also, my program is currently doing 1.19 x 10^56 loops"
    What are you doing?

    > this is my first real C++ program so go easy on me.
    I see no code...
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Would it be as simple as disassembling my program and then compiling it with the assembly code ? I'm just looking for a simple method right now rather than digging into my code.
    You're saying that you'd rather learn Assembly, disassemble your program, and then convert it that way to Assembly and recompile it, rather than read your own code? :shakes head:

    Also, I didn't use any classes since I'm not good with them yet. I also didn't use very many functions. Would using either one of these speed it up? I need to cut some major time off of my program.
    And yet somehow you expect to be able to disassemble your code, understand the disassembly, and ... :shakes head:

    Also, my program is currently doing 1.19 x 10^56 loops. As I write more code that will increase and it is already too slow.
    How about you figure out how to get rid of your huge loop, or perhaps optimize there to start? You'll probably want to also just redesign the entire program, because from the sound of it, it's nasty code.

    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Registered User
    Join Date
    Mar 2004
    Posts
    50
    jesus, I said go easy on me.

    My calculations weren't correct. The main loop is only going around 990 times. 990 != 1.19 x 10^56 . I said I was new at this.

    I am very new. I've never had a c++ programming class and it has been 10 years since I had that introduction to pascal class.

    I got some new questions. Is it possible to make a program that generates a number lets say 99.11 , take that number and put into a notepad file or some kind of text file. Then I could write a program later that would search through and find the correct number ? Or lets say it this program would input this value in a spreadsheet or matrix. Thank you for any replies and relax. I'm not programming for a job or as part of my career.

  5. #5
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    why do you have a loop that repeats itself 990 times??????
    As for your other question its called file i/o very easy and very nice
    Code:
    #include <iostream>
    #include <fstream>
    using namespace std;
    
    int main()
    {
      ofstream test("Loser.txt");
      test<<"Hello"<<endl;
      test.close();
    }
    Woop?

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I said go easy on me.
    I did.
    The main loop is only going around 990 times. 990 != 1.19 x 10^56 . I said I was new at this.
    New at what, math? 2^32 is four billion. Let's not talk about 10^56 ok?
    Is it possible to make a program that generates a number lets say 99.11 , take that number and put into a notepad file or some kind of text file. Then I could write a program later that would search through and find the correct number ?
    Yes. It is possible.

    Quzah.
    Hope is the first step on the road to disappointment.

  7. #7
    Registered User
    Join Date
    Mar 2004
    Posts
    50
    did I make a wrong move in my post ?

    Thanks prog-bman for the info. I will probably use it.

    Anyone know the limitations on how many values can be inputted into an excel file or notepad file ? Could you put a million values stretched vertically into one of these files ? That would probably be several MB s.

    Ok, so I've input the values into notepad. How would I read the values or find the one I needed. Lets 99.11 was on the 16th line. Or lets say I wanted to find whatever value was on the 16th line.

  8. #8
    Registered User
    Join Date
    Mar 2004
    Posts
    50
    it repeats 990 times to do permutations.

  9. #9
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    did I make a wrong move in my post ?
    No, not really. I'm always like this. You'll get used to it.
    Anyone know the limitations on how many values can be inputted into an excel file or notepad file ? Could you put a million values stretched vertically into one of these files ? That would probably be several MB s.
    Excel may have its limits, but other than that, the only limits on you writing whatever you feel like to a file are hardware and OS limitations. If you want to make a file and write 1,000,000,000 characters to it, go ahead.

    Rather than us teach you every little thing about the language, one at a time, I'd really suggest you go buy yourself a good book for learning the language, and probably at least one reference type book on the language also. There are of course online references and tutorials, but can you really ever have too many books? (Schildt naturally excluded.)

    You may also want to take a gander at this faq entry on the topic. Also try searching the forums on file IO or the like.

    Quzah.
    Hope is the first step on the road to disappointment.

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > did I make a wrong move in my post ?
    Well not posting code is perhaps one. You didn't state the problem you were trying to solve, nor the program you had written to solve it.
    All you can get in response to that is a bunch of vague generalities which may or may not help you figure something out.

    > Anyone know the limitations on how many values can be inputted into an excel file or notepad file ?
    I think excel is limited to 256 columns and 65536 rows
    Text files can be as big as you want, though historically Windows notepad is limited to 64K of text. Most normal text editors can cope with many megabytes of text.

    > Or lets say I wanted to find whatever value was on the 16th line.
    Normally, you have to read each line one at a time starting at the beginning of the file. You either stop when you've read the required number of lines, or the line contains the required information.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  11. #11
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    >> My calculations weren't correct. The main loop is only going around 990 times. 990 != 1.19 x 10^56 <<

    That's lucky! To execute a loop that big, at a billion iterations per second, would take roughly 90 years!

  12. #12
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    #include <iostream>
    int main( void )
    {
     for(int i=0;i<10;i++)
      for(int i=0;i<10;i++)
       for(int i=0;i<10;i++)
        for(int i=0;i<10;i++)
         for(int i=0;i<10;i++)
          for(int i=0;i<10;i++)
           for(int i=0;i<10;i++)
            for(int i=0;i<10;i++)
             for(int i=0;i<10;i++)
              for(int i=0;i<10;i++)
               for(int i=0;i<10;i++)
                for(int i=0;i<10;i++)
                 for(int i=0;i<10;i++)
                  for(int i=0;i<10;i++)
                   for(int i=0;i<10;i++)
                    for(int i=0;i<10;i++)
                     for(int i=0;i<10;i++)
                      for(int i=0;i<10;i++)
                       for(int i=0;i<10;i++)
                        for(int i=0;i<10;i++)
                         for(int i=0;i<10;i++)
                          for(int i=0;i<10;i++)
                           for(int i=0;i<10;i++)
                            for(int i=0;i<10;i++)
                             for(int i=0;i<10;i++)
                              for(int i=0;i<10;i++)
                               for(int i=0;i<10;i++)
                                for(int i=0;i<10;i++)
                                 for(int i=0;i<10;i++)
                                  for(int i=0;i<10;i++)
                                   for(int i=0;i<10;i++)
                                    for(int i=0;i<10;i++)
                                     for(int i=0;i<10;i++)
                                      for(int i=0;i<10;i++)
                                       for(int i=0;i<10;i++)
                                        for(int i=0;i<10;i++)
                                         for(int i=0;i<10;i++)
                                          for(int i=0;i<10;i++)
                                           for(int i=0;i<10;i++)
                                            for(int i=0;i<10;i++)
                                             for(int i=0;i<10;i++)
                                              for(int i=0;i<10;i++)
                                               for(int i=0;i<10;i++)
                                                for(int i=0;i<10;i++)
                                                 for(int i=0;i<10;i++)
                                                  for(int i=0;i<10;i++)
                                                   for(int i=0;i<10;i++)
                                                    for(int i=0;i<10;i++)
                                                     for(int i=0;i<10;i++)
                                                      for(int i=0;i<10;i++)
                                                       for(int i=0;i<10;i++)
                                                        for(int i=0;i<10;i++)
                                                         for(int i=0;i<10;i++)
                                                          for(int i=0;i<10;i++)
                                                           for(int i=0;i<10;i++)
                                                            for(int i=0;i<10;i++)
                                                             std::cout<< "Hello world!";
     return 0;
    }
    You'll forgive me for not using 4 space indentation, I'm sure.

    Quzah.
    Hope is the first step on the road to disappointment.

  13. #13
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Awwww - you didn't put it all on one line
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  14. #14
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    #include <iostream>
    int main( void ){for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)for(int i=0;i<10;i++)std::cout<<"Hello world!";return 0;}
    How about 2 lines? It goes with my sig. It's its horizontal counterpart.

    Quzah.
    Hope is the first step on the road to disappointment.

  15. #15
    Registered User
    Join Date
    Mar 2004
    Posts
    50
    now flip your name upside down and change your join date to 1000 B.C.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  2. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  3. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM