Measuring the memory usage of a algorithm