Worst case code time analysis

Discussion in 'Embedded Systems and Microcontrollers' started by aamirali, Jul 29, 2014.

  1. aamirali

    Thread Starter Member

    Feb 2, 2012
    I have written a code:

    I have sample data. then according to sampled data I have 48 cases. Depending upon data all or different cases may execute. Individual case time tme again may vary according to data value passed.

    So how to calculate worst case I mean max time taken by loop.

    1. This is very general example I took. I want to know is there any software/tool available which can do this analysis like pass sample data & tell me that for these values code will crash & these values max time will be taken
  2. NorthGuy

    Active Member

    Jun 28, 2014
    A straightforward approach is to insert after sample_data() some code which will alter data to produce worst case scenario, then run and time it.
  3. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    If I read your post correctly, the data can be classified in one of 48 ways. So I'd modify the program 48 times as NorthGuy suggests, once for each possible case. It's possible to do this in a loop. It's also possible to insert a second loop, to repeat each case n times; like 100 times. Depending on the hardware this code is running, automatically timing and reporting on each case may be possible.

    I also interpret you post to say you are concerned that one or more of the cases may cause your code to crash. By simulating the operation in this manner, identifying the cause of a crash will become apparent.

    You may also be able to predict the worst case by reviewing your code, but testing code automatically like this is good practice.