Thread: c program to decrement a large number with minimum execution time

  1. #1
    Registered User
    Join Date
    Jul 2015
    Posts
    1

    c program to decrement a large number with minimum execution time

    I have tried to decrement a large integer value with less execution time, to achieve that i am declaring a variable with register keyword like register unsigned int value from this i have not received any optimization results while run this program with/without using this register keyword. please correct me if i am wrong. and please share if we have any other method to decrement a larger number with minimum execution time.
    program mentioned here is just for example with register keyword(one of the optimization method to reduce execution time) main aim of this question is how to decrement a larger number with minimum execution time.
    Code:
    #include <stdio.h> #include <time.h> unsigned int decrement(unsigned int value); main() { clock_t start, end; double cpu_time_used; register unsigned int value; value = 4294967; start = clock(); decrement(value); end = clock(); cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC; printf("cpu_time_used %lf\n",cpu_time_used); } unsigned int decrement(register unsigned int value) { int i; for(;value;value--) { printf("loop value %u\n",value); } return 0; }
    Last edited by Raja Sami; 07-13-2015 at 11:49 PM. Reason: typo corrected

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    It is quite likely that the bulk of the time is spent in output rather than in the decrement. I posit that chasing this micro-optimisation is barking up the wrong tree, and it is quite possible that the right optimisation is to simply write:
    Code:
    value = 0;
    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

  3. #3
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    Must be a full moon.

    Anyway, the magnitude of the integer value has no bearing on the time to decrement it.
    And the register keyword is pretty much useless.
    Just compile with optimizations and that's the best you can do.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 03-06-2012, 10:58 AM
  2. on what program execution time depends upon
    By suryak in forum C Programming
    Replies: 2
    Last Post: 05-19-2011, 01:03 AM
  3. intentially create program with large run-time memory
    By dsollen in forum C++ Programming
    Replies: 3
    Last Post: 11-02-2009, 12:07 PM
  4. How to get program execution time
    By pobri19 in forum C++ Programming
    Replies: 8
    Last Post: 01-20-2009, 07:45 AM
  5. Windows 2k Dos- Program Execution Time
    By maththeorylvr in forum C Programming
    Replies: 1
    Last Post: 03-17-2005, 10:03 PM

Tags for this Thread