-
Active Member
Loop Performance Issue with toUpperCase()
Hello to everyone.
I'm attempting to use the toUpperCase() function to convert a huge array of strings to uppercase. However, the process appears to be taking longer than planned, and I fear it may be affecting the performance of my application, which is unusual, so I checked through many documents but couldn't figure it out, so I found this post by scaler. Here's a condensed version of my code:
Code:
let inputArray = ["apple", "banana", "cherry", ...]; // Around 10,000 elements
let uppercaseArray = [];
for (let item of inputArray) {
uppercaseArray.push(item.toUpperCase());
}
console.log(uppercaseArray);
Is there a faster way to apply the toUpperCase() function to a full array without sacrificing performance?
I appreciate your assistance and recommendations!
-
This does not seem to be a WoW emu specific problem.
The general advise for expensive logic is to parallelise it where possible.
So instead of having 1 loop that converts each item, use a algorithm like map reduce.
Map -> toUpperCase -> Split over many threads.
Reduce -> collect results until you have a single array
MapReduce - Wikipedia
-
Post Thanks / Like - 1 Thanks
hackerlol (1 members gave Thanks to stoneharry for this useful post)