Thread: Assignment position dramatically affecting performance

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    88

    Assignment position dramatically affecting performance

    Say I have the code below:
    Code:
    #include <dbi.h>
    
    using std::cout;
    
    int main()
    {
    	clock_t t_start = clock();
    	clock_t t_fin;
    
    
    	DBI *dbh = new DBI;        // position 1
    	cout<< "Content-type: text/html\n\n";
    
    	for( long i=0; i<1000000000; i++ )
    		;
        cout<< "Counted to a billion!<br />";
    
    	//DBI *dbh = new DBI;        // position 2
    
    	char *env_qs = getenv("QUERY_STRING");
    	if( *env_qs == NULL )
    		cout<< "exe failed it's purpose<br />";
    	else
    		cout<< "You said <span style=\"font-family:sans-serif;\">\""
    	<< env_qs << "\"</span> to me<br />";
    
    	t_fin = clock();
    	cout<< "code took about " << (double)(t_fin - t_start) / CLOCKS_PER_SEC << " secs";
    
    	delete dbh;
    	return 0;
    }
    Note that DBI *dbh isn't used. That should be irrelevant, since its constructor doesn't care.

    The app usually takes ~2.5-2.8 secs to complete when the commented line is in position 2, but ~3.75-4 secs in position 1. I am utterly baffled that there is a difference, let alone the (relatively) huge discrepancy that comes up here. I've made sure the difference is consistent, and not just me but I haven't a clue as to explaining it. Any suggestions?
    Last edited by drrngrvy; 10-15-2005 at 05:04 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. Replies: 1
    Last Post: 10-27-2006, 01:21 PM
  3. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 06:23 AM
  4. Problem with linked list ADT and incomplete structure
    By prawntoast in forum C Programming
    Replies: 1
    Last Post: 04-30-2005, 01:29 AM
  5. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM