New answers tagged performance
0
votes
Print a hollow Rhombus
Imagine you know someone beginning Java three years after writing this.
You show them the code presented: Can they easily find out from looking at the code what it is to do?
Whether it is correct? Do ...
2
votes
Optimizing __getitem__ for a bioinformatics script in Python
new to the area and I've been learning while developing
Great, welcome!
Software is almost as interesting as biology.
And it's much less messy.
measurements
much longer for larger files
“When you ...
3
votes
Spatial radius search in Boid simulation
Nice problem!
I gotta tell ya, QuadTrees is definitely the appropriate datastructure.
And it's just not that hard.
Let coord be the bit interleaving of ...
3
votes
Spatial radius search in Boid simulation
The slowness comes from drawing
Your query() function is actually quite efficient. The problem comes from drawing the boids. If you remove the calls to ...
2
votes
Pentomino solver in Python
Kudos on tackling such an interesting problem!
design of Public API
...
0
votes
Sum of all possible concatenations of array values
You can reduce the line count of Donald's answer to improve readability by:
Removing the for loop with Array.reduce(),
Using ...
1
vote
Trailing Digits
finally I found a link with a lot of examples. I found trailingdigits.py with a much more elegant approach github.com/RussellDash332/kattis/blob/main/src/… and another webpage that shows more detail ...
1
vote
Accepted
Given an array, remove zero or more elements to maximize the reduction where you add odd values and subtract even values
You could simply use this pattern:
[greatest value, smallest value, greatest value, smallest value, ...]
local maximum, local minimum, ...
That means, go until ...
2
votes
Trailing Digits
Picture yourself coming back to "V1 code" a decade from now:
You can read it, you can run it.
Do you know what does, and to what end?
Name things for what they are good for.
...
2
votes
Finding a distinct triplet where the sum of the values is divisible by a given number
Its possible to solve the problem in O(N + D*log(D)) time, using the Fast Fourier Transform (FFT). In a nutshell- reduce each value mod ...
1
vote
Finding a distinct triplet where the sum of the values is divisible by a given number
I'd prefer divisible_triplets(integers, divisor).
And it deserves a docstring.
You state I want to count the number of … -
I don't want to be caught telling people ...
2
votes
Finding a distinct triplet where the sum of the values is divisible by a given number
One of the weaknesses of the code is that we're actually finding every triple. We're not required to do so - the only thing that matters is the count of results.
That means that we can group the ...
2
votes
Finding a distinct triplet where the sum of the values is divisible by a given number
We can preprocess the array by setting each a_i to a_i modulo d.
We're asked for a sum of ...
1
vote
Finding a distinct triplet where the sum of the values is divisible by a given number
One improvement might be derived from changing every array entry to its modulo 5 value:
...
2
votes
2
votes
Project Euler 60: Prime Pair Sets
Eliminate 2 and 5 from your sieve!
Any 2+ digit prime cannot end in a 2 or a 5, as these will be multiples of ...
1
vote
another Merge Sort
Code risks invoking undefined behavior:
None of the calls to malloc() have their return values checked.
...
1
vote
another Merge Sort
Is there any other good practices that I've missed to follow in my try?
Sort stability
Agree with @Martin York code has stable sort concerns.
A stable sort keeps the array elements in the same order ...
3
votes
Accepted
another Merge Sort
Three things pop out to me:
This is not a stable sort.
Probably does not matter, as you currently only support integers.
This only support integer sorts.
If you look at the standard qsort you will ...
1
vote
Python: Detect if a number is divisible by any number in a list
i is not divisible by a factor of step_size iff gcd(i, step_size) == 1. Otherwise, that gcd ...
2
votes
Python: Detect if a number is divisible by any number in a list
natural log
I'm unhappy with this expression:
prime_count = ... len(str(number)) // 3
Since the length computes log10(),
and <...
3
votes
Accepted
Python (API requests)
In a pathname like logs/err-logs.log, the -logs suffix seems redudnant.
one level down
Based on ...
2
votes
Accepted
Distance on a unit grid
min_x = min(abs(x1 - x2),
dist_x = (x1 - x2) ** 2
We can see the border cross algorithm and the standard algorithm are ...
4
votes
Find the closest named color
Incorrect calculation of color distance
sRGB is a logarithmic scale
RGB (AKA sRGB) as used by the browser is a logarithmic scale (apart from the very darker values which are linear)
Your calculation ...
3
votes
Accepted
Multi producer/consumer lock-free queue
This is not lock-free
Unfortunately, your queue is not lock-free. Basically, your _canUpdate is used as a lock. Consider a thread that has taken the lock, so it's ...
1
vote
Optimisation: Fastest way to multiply every number in an array by 2
Thanks to @harold the goal of getting under 50 ns was achieved with loop unrolling and removing the unnecessary copy instruction. The code below is similar to his but is bithacked and instead of using ...
1
vote
Optimisation: Fastest way to multiply every number in an array by 2
A couple of further things we can do are:
Use Vector256.StoreUnsafe for the store. It's not a huge deal, but going by the assembly, the ...
0
votes
Accepted
How to optimize the player movement code like in Tomb Of The Musk game?
In terms of performance what I have done is removed unnecessary method calls and helped out your branch predictor by removing if/else statements.
What I have mainly done though is to enhance code ...
1
vote
Optimisation: Fastest way to multiply every number in an array by 2
After a suggestion by @harold a further 15ns has been shaved off by using the Vector.ShiftLeft(v, 1) method instead of doing the multiplication and secondly to use <...
1
vote
Optimisation: Fastest way to multiply every number in an array by 2
Upon a suggestion from @iSR5 I have reimplemented the SIMD instruction using the MemoryMarshall method. This has shaved off a further 60ns. I think SIMD instructions and the memory marshall method go ...
3
votes
Optimisation: Fastest way to multiply every number in an array by 2
I have shaved off about 100ns with the following improvements: used a shift operator to perform the multiplication by 2, since I know that my Vector<int>.Count...
3
votes
Accepted
Convert 64-bit Gray code to integer
While it's not your code, I'll point out that the routine from OEIS can be significantly shortened by using an assignment expression, available since Python 3.8:
...
6
votes
Convert 64-bit Gray code to integer
I assume that your first example is depicted in human-legible (i.e. big-endian) order. The right-most digit is indeed then the least-significant digit. When you call ...
-3
votes
0
votes
calculate the number of ways to pick two different indices
use boring business vocabulary
Your task ... two different indices i < j, such that a[i] + a[j] ...
for (let e = ...
if ((a[i] + a[e]) ...
...
Top 50 recent answers are included
Related Tags
performance × 9012python × 2311
java × 1274
c++ × 1057
algorithm × 1000
c# × 873
javascript × 837
python-3.x × 637
programming-challenge × 636
beginner × 612
c × 530
strings × 373
array × 325
php × 296
vba × 275
excel × 275
sql × 257
numpy × 241
primes × 214
jquery × 207
matrix × 182
python-2.x × 179
image × 177
multithreading × 175
recursion × 157