New answers tagged performance
4
votes
Accepted
Speed up searching for the lowest element that is not in the array
You present code for a typical "challenge" submission without ever spelling out the problem in the source code.
What's more, you miss the opportunity to declare a suggestively named business ...
4
votes
Accepted
A search function that searches for a contact inside a vector
Keeping in mind that it is impossible to give good answers, or a good review, without a clear context of what the code is for or how it is going to be used. A single member function—not even a full ...
11
votes
Accepted
Optimized data structure mapping finite set of integers to values in C++
Design review
You are massively over-complicating the problem
You call it a map, and you talk about using integers as keys. But… in reality, because your keys are small, you are just using indices. So ...
4
votes
Optimized data structure mapping finite set of integers to values in C++
range check
There's no provision for validating key against N,
not even in a debug build.
...
9
votes
Beginner level password generator optimization
Security
The documentation for the random module gives the following warning:
Warning: The pseudo-random generators of this module should not be used for security ...
13
votes
Accepted
Beginner level password generator optimization
Remarks:
Bug: you have an extra letter sneaking in with for req in range(0, nr_letters + 1):, making your output longer than it should be. That should be ...
6
votes
Optimizing Pi Estimation Code
You can calculate Pi using numerical integration of the circular arc-segment centred at (0,0), from the point (radius, 0) to <...
3
votes
Reversing vowels in a string
All good things have already been said, alas.
Perhaps a solution using numpy, where you can use arrays to select members of arrays.
...
3
votes
Optimizing Pi Estimation Code
on the pure optimization part you must precompute more
while x**2 + y**2 <= rs:
if (x*1.00001)**2 + (y*1.00001)**2 <= rs:
can be faster if you precompute ...
4
votes
Optimizing Pi Estimation Code
scientific notation
effectively work out 100 trillion coordinates (radius of 10,000,000)
Prefer to describe these numbers as
\$10^{14}\$ and \$10^7\$,
which immediately makes the "squared" ...
3
votes
Reversing vowels in a string
The logic behind your function is this:
Create a list of the vowels in the target string
Reverse this list
Iterate through the indices pointing to each character of the target string
For each index, ...
3
votes
Reversing vowels in a string
Benchmarks
Highly likely this is from LeetCode, so I benchmarked our solutions there. Times from three submissions:
...
1
vote
Reversing vowels in a string
I instantly thought about looping the characters in the string directly instead of looping by the index and also wanted to test just adding to a string instead of the conversion to and from a list. ...
0
votes
Reversing vowels in a string
The biggest problem with the code presented is that it does not document what it is to accomplish:
See how your take and MatBailie's do a substitution based on the position in a/the sequence of vowels ...
10
votes
Reversing vowels in a string
This is your mistake: if s[i] in v:
Simply change that to if s[i].lower() in vowels:. Then it easily gets accepted where I ...
7
votes
Reversing vowels in a string
You could convert vowels into a set for a slight improvement, since sets are quicker to check for a certain value than lists.
For your second loop, you don't need ...
10
votes
Reversing vowels in a string
A set is slightly faster when using in, and a comprehension is slightly faster than a loop with append()
...
2
votes
Implement Huffman code in C17
Be concise; be expressive
Code is a recipe expressing a series of operations on data values to achieve a goal.
It's ironic that this code whose purpose is to compress (and decompress) data should be ...
3
votes
Accepted
String art program in Python using PyTorch
Strategies to speed up the code:
Instead of computing all the lines in one large array, then picking one, you should compute one line at the time, and keep only the best one iteratively. Loops in ...
2
votes
Golang Optimize Unzipping FiIes
(It's going to be difficult to actually try this code, since it's not self-contained. Better to have either a single
file that can be run directly, or link a repository that can be cloned and built as-...
0
votes
A thread-safe performant Money Transfer API in Java
The approach is flawed from the start. An Account does not perform money transfers. Accounts are just data objects. A money transfer is done by a service, that ...
3
votes
A thread-safe performant Money Transfer API in Java
This is not code where you should be remotely worried about the performance. Maximize readability until you have a tested, proven bottleneck.
What happens when an external thread acquires and does not ...
7
votes
Accepted
Implement Huffman code in C17
Valgrind reports no leaks or errors. Good job on that, and welcome to programming and C. To complement @user555045's nice answer, this review would be about the intricate details of the code, the ...
6
votes
Implement Huffman code in C17
This will be a somewhat higher-level review of the algorithms and approach to Huffman coding, I'll let other people worry about the intricate details of the code and the issues brought up in the ...
1
vote
Project Euler 127 - abc-hits
Because c gets quite large, there is a small advantage to altering your short cut test to avoid a multiplication inside the loop on ...
1
vote
Accepted
CSV Data Plotting Program using CsvHelper in C#
Highlights :
CSV_Processing should be ProcessCsvFile or ProcessFile.
...
2
votes
Accepted
Srivastava multivariate Fox H function in MATLAB
Avoid Symbolic Math for Numerical Evaluations:
Replace symbolic computations with MATLAB's numeric gamma function. Symbolic math should only be used for symbolic ...
5
votes
Srivastava multivariate Fox H function in MATLAB
There are some obvious inefficiencies in the code that I can point out.
The profiler shows that most time is spent doing symbolic math. You use symbolic math to compute the product of a series of ...
3
votes
Accepted
Project Euler 127 - abc-hits
Given that: \$GCD(a,b)=GCD(a,c)=GCD(b,c)=1\$
Since \$a\$, \$b\$ and \$c\$ have no common divisors then it also follows that: \$GCD(rad(a),rad(b))=GCD(rad(a),rad(c))=GCD(rad(b),rad(c))=1\$
And: \$rad(...
8
votes
Project Euler 127 - abc-hits
Possible Bug
Whenever c is odd, for a in range(1, c // 2) misses an a, b combo.
For example: ...
Top 50 recent answers are included
Related Tags
performance × 9105python × 2344
java × 1280
c++ × 1077
algorithm × 1008
c# × 879
javascript × 837
programming-challenge × 646
python-3.x × 644
beginner × 623
c × 546
strings × 375
array × 326
php × 298
vba × 275
excel × 274
sql × 260
numpy × 241
primes × 218
jquery × 206
matrix × 182
image × 181
multithreading × 180
python-2.x × 179
recursion × 158