# Time: Using It to Compare Resource Use

Time – time a simple command or give resource usage (linux man-pages)

## Example

In this example I’m going to use the time command to check my character indexing script (github).

In brief these script’s first determine the total unique combinations of a given string of characters, and then returns the where the string input would belong in that alphabetical index.

For this case, I’m going to use an alphabetical 10 character string. Which has a total of 3628800 possible combinations (10!).

## Dictionary Lookup

The first script solves this problem thru a dictionary lookup. First the unique combinations are generated into an array, then the script searches the array for the input string, once found the index is returned.

In this case, 10! combinations generated a whopping 1.23gb array in memory, taking 1 minute and 48 seconds to complete.

## Algorithm

For the case of an input string made up of unique characters, the results per character can be determined when the array length is divided by the amount of unique characters (10!/10) = 362880. Knowing the possibilities per character lets the algorithm set the range.

Multiplying the possibilities per character by the alphabetic disorder of the leading character found by looking up the leading character inside an alphabeted list, and using the index as the integer. In this case, 362880 * 0 = 0.

This concept continues in a recursive loop eliminating the the leading character, repeating as such: (9!/9, 8!/8 etc), while summing the iteratively smaller minimum range.

Once the input string is exhausted, the minimum ranges are summed, and added by 1 to convert back to an ordinal number system. This is because the first position of a list or an array is always 0, being first is otherwise referred to as 1.

Meanwhile this algorithm really sped things up. Fourty milliseconds compared to 108 seconds of computation time. While using 6.9megabytes of memory in comparison to 1,237MB.