Thread: Some help with make my programs faster

  1. #1
    Registered User Sshakey6791's Avatar
    Join Date
    Nov 2008
    Location
    -
    Posts
    57

    Question Some help with make my programs faster

    I made some programs at my house and they run find but I trying them out on my schools computer and it runs slow. any tips on how I can make my codes better so that it runs the same for most computer?
    "Blood you have thirsted for -- now, drink your own!"
    (Dante)

  2. #2
    Banned
    Join Date
    Dec 2008
    Location
    Maputo, Mozambique
    Posts
    82
    Maybe your computer at school doesn't have enough memories for your programs.

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    My tip to make your code faster: change your algorithm.

    Without any info on the code, there's nothing more I can say.

  4. #4
    Banned
    Join Date
    Dec 2008
    Location
    Maputo, Mozambique
    Posts
    82
    Can you show some of your codes? Maybe someone will fix it for u out of the goodness of there heart.

  5. #5
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    First, make sure it's CPU-bound. If it's I/O bound (to harddrive, for example), there is not much you can do except changing the algorithm.

    Otherwise profile the code, look for the performance bottleneck, and try to rewrite it to make it faster.

    But yeah, nothing much we can do without seeing the code.

  6. #6
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by Sshakey6791 View Post
    I made some programs at my house and they run find but I trying them out on my schools computer and it runs slow. any tips on how I can make my codes better so that it runs the same for most computer?
    Can you create a gallon of gasoline that goes for 45 miles no matter what kind of car you put it in?
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    We can't give you specific help without at least SOME understanding of what your code does.

    I wrote up some hints on how to measure/improve performance:
    http://apps.sourceforge.net/mediawik...d_optimization

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #8
    Registered User Sshakey6791's Avatar
    Join Date
    Nov 2008
    Location
    -
    Posts
    57

    Here's a program a made in my 11th grade class

    Code:
    #include <iostream>
    #include <time.h>
    #include <math.h>
    #include <stdlib.h>
    #include <stdio.h>
    
    
    using namespace std;
    
    int main () {
    
    
    	srand ( time ( NULL ) );
    
    	short int NumGuess;
    	int InvisableNum = ( rand () % 100 ) + 1;
    	short int num = 0;
    
    
    	system("COLOR 7");
    
    	cout << " \t \t Guessing Game" << endl << endl;
    
    
    	do { 
    
    
    
    		cout << "Guess a number between 1 - 100 (0 to exit): ";
    		cin >> NumGuess;
    
    
    
    		if ( NumGuess > InvisableNum ) {
    
    				cout << endl;
    				cout << "To High! " << endl << endl;
    
    
    		} else if ( NumGuess < InvisableNum ) {
    
    				cout << endl;
    				cout << "To Low! " << endl << endl;
    
    		}
    
    		num++;
    
    
    		if ( NumGuess == InvisableNum ) {
    
    				cout << endl << endl;
    
    				cout << "You are right!!, it took you " << num << " trys" << endl << endl;
    				cout << endl;
    
    		} 
    
    	} while ( NumGuess != InvisableNum ); 
    
    		system("pause");
    
    
    	return(0);
    
    
    }
    Very basic but it's the only one I have on me at school : (
    "Blood you have thirsted for -- now, drink your own!"
    (Dante)

  9. #9
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You are saying that this program runs too slow?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  10. #10
    The larch
    Join Date
    May 2006
    Posts
    3,573
    I guess the only things that might be too slow are the system calls. Don't use external programs for these things or just live with it...
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  11. #11
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    838
    that should run like gangbusters on a 286

  12. #12
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    On a windows platform, it MAY run slow if the graphics card isn't accellerating certan bitblt l operations used for scrolling the screen. Try switching to full-screen mode (ALT-ENTER in a command prompt). Or simply reduce the number of "endl" to reduce the amount of scrolling in the first place.

    But yess, I agreee with m37h0d - it shouldn't run slow on any computer produced in the last 15 years or so.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to make a Packet sniffer/filter?
    By shown in forum C++ Programming
    Replies: 2
    Last Post: 02-22-2009, 09:51 PM
  2. PLEASE help me with these linux programs how to make them
    By pksucks in forum Linux Programming
    Replies: 1
    Last Post: 10-22-2008, 07:51 AM
  3. Critique / Help me make this program run faster.
    By Mastadex in forum C++ Programming
    Replies: 10
    Last Post: 06-26-2004, 11:58 AM
  4. how to make files
    By quiksilver9531 in forum C++ Programming
    Replies: 6
    Last Post: 02-22-2002, 06:44 PM