how can we calculate excution time and memory needed

This is a discussion on how can we calculate excution time and memory needed within the C Programming forums, part of the General Programming Boards category; Hi I'm having a exercise which started with "Time Limit: 1000MS Memory Limit: 65536K" what does that mean?? and how ...

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    72

    Wink how can we calculate excution time and memory needed

    Hi
    I'm having a exercise which started with "Time Limit: 1000MS Memory Limit: 65536K" what does that mean??
    and how can we calculate memory and time ???

    thanks in advance
    proud to be from aui www.aui.ma and also a great elton john's fan

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    That CAN be difficult.

    You need to understand what you are about to store in memory (including or excluding of code, depending on the definition) - It's pretty easy to write a piece of code to do sizeof() on some types to get a starting point for the basic data types [or you can just calculate it by hand by looking at the data type and using the individual sizes of variables, e.g. 4 bytes for a int, 4 bytes for a pointer, 2 bytes for a short, etc, etc]

    By the way, on average, a line of code is approximately 10-12 bytes - but this DOES depend on the compiler, the architecture of the processor, and how complex you make your lines.

    Execution time is fairly trivial on small simple processors, but modern processors are much more complicated, as cache hit rate and memory latency makes a big impact on the data (instruction) throughput.

    Also, in most environments, there are tools to analyze the executable file for the size of the code and data contents - the tools vary from one system to another.

    --
    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.

  3. #3
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    you can use gethrtime() to time how long your program takes. Not sure about the memory though, it probably means the amount of memory that you allocate for your variables...

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >what does that mean??
    It probably means that your program has to run within the time and space constraints. In other words, when you run it, it can't take longer than 1000ms and can't use more than 65536K of memory.

    >and how can we calculate memory and time ???
    A profiler can give you this kind of information.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help! -Linked Lists, Memory Allocation, Time Steps, Debugg
    By MetallicaX in forum C Programming
    Replies: 2
    Last Post: 03-14-2009, 08:50 PM
  2. To find the memory leaks without using any tools
    By asadullah in forum C Programming
    Replies: 2
    Last Post: 05-12-2008, 07:54 AM
  3. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 08:32 AM
  4. Manipulating the Windows Clipboard
    By Johno in forum Windows Programming
    Replies: 2
    Last Post: 10-01-2002, 09:37 AM
  5. Is it necessary to write a specific memory manager ?
    By Morglum in forum Game Programming
    Replies: 18
    Last Post: 07-01-2002, 01:41 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21