I hope this helps . How can I increase the performance of the following code: , Do it as one function call: code :
$text = str_replace(["A","f","c","4"], ["B","F","S","G"], $text);
Share :

speed up replace NaNs with last nonNan value
By : James
Date : March 29 2020, 07:55 AM
wish of those help Since you want the previous nonNaN value, I'll assume that the first value must be a number. code :
while(any(isnan(input)))
input(isnan(input)) = input(find(isnan(input))1);
end

How can I speed up/replace my double for loops?
By : RockIOS
Date : March 29 2020, 07:55 AM
I hope this helps . Make threads. You can find out how many files you need to look through and possibly split it across 4 threads. This will make the process much faster as it will allow the documents to be read at the same time You could start by making a method that accepts a list of files then loop through those. Then you could pass a few sections of the main list to the method and run them in threads. That should provide a decent increase in speed

How to replace SortedSet with something faster or speed it up
By : Richard Springstead
Date : March 29 2020, 07:55 AM
this will help I'm trying to resolve the problem from LeetCode https://leetcode.com/problems/nthmagicalnumber/ . I can submit my solution, but I would like to speed it up, I suppose one of the ways to do so is remove using of collections , This is an example of how doing with array only instead of SortedSet: code :
import java.util.Arrays;
import java.util.Objects;
class Solution {
private static final int MODULO = (int) (Math.pow(10, 9) + 7);
private static int modulate(final long result) {
return (int) (result % MODULO);
}
private static Integer[] steps(final int smaller, final int larger) {
final int lcm = lowestCommonMultiple(smaller, larger);
final int max = lcm / smaller;
final int min = lcm / larger;
final Integer[] result = new Integer[max * 2];
int pos = 0;
for (int i = 1; i <= max; i++) {
result[pos++] = (i * smaller);
if (i <= min) {
result[pos++] = (i * larger);
}
}
return Arrays.stream(result)
.filter(Objects::nonNull)
.sorted()
.distinct()
.toArray(Integer[]::new);
}
private static long nthNonZeroMagicalNumber(final int N, final int smaller, final int larger) {
final Integer[] stepsInCycle = steps(smaller, larger);
final long lcm = stepsInCycle[stepsInCycle.length  1];
final int inOneCycle = stepsInCycle.length;
final int fullCycleCount = N / inOneCycle;
int count = fullCycleCount * inOneCycle;
final long evaluated = fullCycleCount * lcm;
if (count == N) {
return evaluated;
}
final int remainder = N  count  1;
return stepsInCycle[remainder] + evaluated;
}
private static int greatestCommonDenominator(int a, int b) {
while (b > 0) {
int temp = b;
b = a % b;
a = temp;
}
return a;
}
private static int lowestCommonMultiple(final int a, final int b) {
return a * (b / greatestCommonDenominator(a, b));
}
public static int nthMagicalNumber(final int N, final int A, final int B) {
if (N == 0) {
return 0;
} else if (A == B) {
final long result = (long) A * (long) N;
return modulate(result);
} else if (N == 1) {
return modulate(Math.min(A, B));
}
return modulate(nthNonZeroMagicalNumber(N, Math.min(A, B), Math.max(A, B)));
}
}

Speed up a VBA Replaceloop possible or use other method?
By : Nifilo
Date : March 29 2020, 07:55 AM
this one helps. You might benefit from this valuable piece of text: https://www.microsoft.com/enus/microsoft365/blog/2009/03/12/excelvbaperformancecodingbestpractices/ code :
Dim arrData as Variant, arrSource as Variant, k as long
arrData = wsCheck.Range("Data").value2 'this creates a twodimensional array with rows on the first and columns on the second index
arrSource = wsSource.Range(...).value2
'loop through rows I suppose
for k = LBound(arrData,1) to UBound(arrData,1)
if arrData(k, yourColumn) = ... then
arrData(k, yourColumn) = arrSource(rowhere, columnhere)
endif
next k
wscheck.range("Data") = arrData

How to speed up or replace the nested loops
By : user3720047
Date : March 29 2020, 07:55 AM
like below fixes the issue I'm not sure exactly which library you are using to manipulate what looks like workbook sheets, however you shouldn't need to set sht1 every time in your inner for loop. Your code could be written as: code :
sht1 = wb.sheets['Pallet Configurations']
letters = ['A','B','C','D']
for i in range(66):
for j in range(len(letters)):
val = (sht1.range(letters[j] + str(i+2)).options(numbers=str).value)
valueList[j].append(val)
sht1 = wb.sheets['Pallet Configurations']
letters = ['A','B','C','D']
for i in range(66):
for j in range(len(letters)):
letter = str(letters[j])
vals = (sht1.range("{0}{1}{0}{2}".format(letter, "2:", "66").options(numbers=str).value)
valueList[j].extend(val)

