Adjusted code for testing memory usage and time consumption.