Every program instruction costs a set amount of processor time, and there is also memory cost for running program.
Sometimes we can talk of other costs such as printer paper pages used or HDD space taken.
Program running costs depend on algorithm used.
Costs usually depend on amount of data processed, that can be measured by proper mathematical function.
There can be optimistic costs, average costs, pessimistic costs.
Time is usually measured in algorithmic steps, amount of most 'expensive' operations done by algorithm.
Memory used by algorithm is usually measured by amount of memory cells used.
Costs can be precise: for example average_processor_time_cost(n) = n3 + 17 steps, average_memory_cost(n) = 0.5 · n2 + 3 memory cells.
Costs can also be written in asymptotic notation O(n).
O(f(n)) means that f(n) is an approximate value limited by upper asymptote for n ≥ n0 where n0 is a constant.
for example, classic sorting algorithm might have asymptotic time cost of O(n · log(n)), and parallel sorting algorithm might have asymptotic time cost of O(log2 n).
Computer Program can be optimized to perform better in certain area at cost of other areas, other things as well.
For example, there can be memory optimization if we recalculate partial results at each algorithmic steps to not store them in memory.
For example, there can be speed optimization if we use memory cache to store data retrieved from HDD and take it from cache if it's available before trying to read from HDD. That way most often read data will be available in memory cache and we won't need to read it from HDD, as it is slow operation.
For example, there can be programmer time cost optimization if we sacrifice quality of software to finish software sooner (programmers are usually paid per hours of work). That type of optimization leads to increased software production & maintenance costs soon after, i should add.
Programmer's time saved - for example thanks to object orientation - can be used for other types of optimization, i should add as well.
Source: My partial education, .
See also, if You wish: Optimization Triad.