Thread: Huh?

  1. #1
    Burning in Hell! Luigi's Avatar
    Join Date
    Nov 2002
    Posts
    117

    Exclamation Huh?

    Ok , consider this..

    Code:
    
    #include <iostream>
    #include <time.h>	// for clock()
    #include <stddef.h>	// for size_t
    #include <string.h>	// for memcpy()
    using namespace std;
    
    void copy_with_pointers(const char *src, char *dst, size_t n)
    {
    	for (size_t k =0; k!=n; ++k)
    		*dst++ = *src++;
    }
    
    
    void copy_with_indices(const char *src, char *dst, size_t n)
    {
    	for (size_t k =0; k!=n; ++k)
    		dst[k] = src[k];
    }
    
    int main()
    {
    	const int n_bytes = 100000;
    	const int n_calls = 100;
    	const char *src = new char[n_bytes];
    	char *dst = new char[n_bytes];
    	
    	
    	// reduce paging effect by accessing all bytes:
    	memcpy(dst, src, n_bytes);
    	clock_t start, end, reftime;
    	
    	
    	
    	// test 1 (reference time)
    	start = clock();
    	for (int k = 0; k!=n_calls; ++k)
    		memcpy(dst, src, n_bytes);
    	end = clock();
    	reftime = end - start;
    	
    
    	
    	// test 2 (pointers)
    	start = clock();
    	for (int k = 0; k!=n_calls; ++k)
    		copy_with_pointers(src, dst, n_bytes);
    	end = clock();
    	
    	cout << "with pointers:" << static_cast<double>(end-start)/reftime << " times slowers then memcpy. \n";
    	
    	// test 3 (indices)
    	start = clock();
    	for (int k = 0; k!=n_calls; ++k)
    		copy_with_indices(src, dst, n_bytes);
    	end = clock();
    	
    	cout << "with indices:" << static_cast<double>(end-start)/reftime << " times slowers then memcpy. \n";
    	
    
    	
    	delete[] src;
    	delete[] dst;
    	
    	return 0;
    	
    }
    I've runned that code few times.. and i kept having different answers.
    sometimes pointers were slowers sometimes indices were.

    Shouldn't i get always the same timing?

    Luigi
    I use code warrior 7.0 on mac os X (10.2)
    thx

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Not at all. Sometimes you are running 18 different programs at once, other times you are running only 1. Even while running 1 you may get different times based on other issues such as how hot the cpu is.

  3. #3
    Neoseeker's master master2000's Avatar
    Join Date
    Dec 2002
    Posts
    101
    Originally posted by master5001
    Not at all. Sometimes you are running 18 different programs at once, other times you are running only 1. Even while running 1 you may get different times based on other issues such as how hot the cpu is.
    how is that poseble the cpu doesn't have a thermo senser so unless it heats up the hardware its not posseble.
    missles on metriods

  4. #4
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Well that isn't what I mean. I am refering to the fact that when a cpu gets too hot your software (even your OS!) starts to become unstable. Surely you've had your computer lockup because of overheating before?

  5. #5
    Neoseeker's master master2000's Avatar
    Join Date
    Dec 2002
    Posts
    101
    Originally posted by master5001
    Well that isn't what I mean. I am refering to the fact that when a cpu gets too hot your software (even your OS!) starts to become unstable. Surely you've had your computer lockup because of overheating before?
    nope
    missles on metriods

  6. #6
    dazed
    Guest

    Talking

    Yep, over overclocking does that

  7. #7
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    Apparently the Intel processors do have built-in thermal sensors. I was surprised to find this out too, but I've had a couple of CPU fans go bad, and the computer got really slow. I"ve read this somewhere too... When the processor overheats, it slows down to protect itself. This ONLY happens when there is something wrong with the CPU cooling.

    I don't know about other processors, althought the little Z180's that we use in our imbedded systems don't have this feature.

  8. #8
    Neoseeker's master master2000's Avatar
    Join Date
    Dec 2002
    Posts
    101
    Originally posted by DougDbug
    Apparently the Intel processors do have built-in thermal sensors. I was surprised to find this out too, but I've had a couple of CPU fans go bad, and the computer got really slow. I"ve read this somewhere too... When the processor overheats, it slows down to protect itself. This ONLY happens when there is something wrong with the CPU cooling.

    I don't know about other processors, althought the little Z180's that we use in our imbedded systems don't have this feature.
    mine is a custom
    33 gigs
    400 ghz ( overload by 50 ghz)
    ati 7500 video card
    ali mother board
    missles on metriods

  9. #9
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    Originally posted by master2000
    mine is a custom
    33 gigs
    400 ghz ( overload by 50 ghz)
    ati 7500 video card
    ali mother board
    ghz=mhz

    The pentium 3 line first introduced some protection against
    overheating,by locking up itself and thereby preventing damaged
    caused by heat,the pentium 4 took it a step further and build
    in a system that could slow down the cpu, the AMD line
    (wich i have in my pc) unfortunatly does not have this,if your
    cooler fails your cpu is gone

  10. #10
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    Originally posted by master2000
    mine is a custom
    400 ghz ( overload by 50 ghz)
    oh that's custom all right.
    hello, internet!

  11. #11
    Neoseeker's master master2000's Avatar
    Join Date
    Dec 2002
    Posts
    101
    my computer (both)
    are perfect they work over night and mine is 400 mhz when its supose to be at 350
    missles on metriods

  12. #12
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    This getting VERY offtopic people

  13. #13
    Neoseeker's master master2000's Avatar
    Join Date
    Dec 2002
    Posts
    101
    Originally posted by moi
    oh that's custom all right.
    what the h%$& is up with your code
    missles on metriods

  14. #14
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    Originally posted by Travis Dane
    ghz=mhz

    The pentium 3 line first introduced some protection against
    overheating,by locking up itself and thereby preventing damaged
    caused by heat,the pentium 4 took it a step further and build
    in a system that could slow down the cpu, the AMD line
    (wich i have in my pc) unfortunatly does not have this,if your
    cooler fails your cpu is gone
    alternatives with AMD:

    some abit motherboards will shut down the system when cpu fan fails (i have one, abit kt7).
    MBM can be configured to shut down system in event of too much heat.
    hello, internet!

  15. #15
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    Originally posted by master2000
    what the h%$& is up with your code
    h%$& <- that english?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Random crashes? huh?
    By cpjust in forum C++ Programming
    Replies: 28
    Last Post: 07-09-2008, 08:41 PM
  2. Replies: 2
    Last Post: 02-28-2008, 11:51 PM
  3. When to say when, huh?
    By correlcj in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 11-17-2002, 09:19 PM
  4. Huh? Can anyone explain?
    By Tarls in forum C++ Programming
    Replies: 11
    Last Post: 03-31-2002, 09:46 AM
  5. Huh? Why doesn't it work?
    By Brian in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 02-21-2002, 04:03 AM