An Efficient Profile-Based Algorithm for Scratchpad Memory Partitioning