Search Results
Search type | Search syntax |
---|---|
Tags | [tag] |
Exact | "words here" |
Author |
user:1234 user:me (yours) |
Score |
score:3 (3+) score:0 (none) |
Answers |
answers:3 (3+) answers:0 (none) isaccepted:yes hasaccepted:no inquestion:1234 |
Views | views:250 |
Code | code:"if (foo != bar)" |
Sections |
title:apples body:"apples oranges" |
URL | url:"*.example.com" |
Saves | in:saves |
Status |
closed:yes duplicate:no migrated:no wiki:no |
Types |
is:question is:answer |
Exclude |
-[tag] -apples |
For more details on advanced search visit our help page |
Performance is a subset of Optimization: performance is the goal when you want the execution time of your program or routine to be optimal.
1
vote
Ellipse-detection algorithm
Too much indexing
Python is not a compiled language. Every time something is indexed, the Python interpreter will redo the index lookup. It cannot determine that a value is unchanged and there is no …
2
votes
Accepted
Block Bootstrap Estimation in Java - Part 2
You've got inefficiency here:
// Sum of a subarray, based on B(x, i, L) -- i is one-indexing
public static double sum(double[] x, int i, int L) {
return IntStream.range(i, i + L)
…
2
votes
performance test the code for finding time taken to fill the disk space
You may be able to speed up the body of the loop using the sum function & list comprehension:
mem = sum( timeTaken // v for v in proc_r )
But the real speed up won’t come until you realize you can …
6
votes
Accepted
Converting an image to black and white
Yes, there are a few things which can be done to speed up your code.
You create local variables width and height. But then you don't use these variables. Instead you use for x in range(img.shape[1] …
8
votes
Accepted
Finds a Character based on distance and health
The tests c.HP > 0 and c.Team != Team are probably blazingly fast tests. Location.Dist(c.GetLocation()) <= AttackRange probably involves the square-root of the sum of the squares of the difference of …
2
votes
Accepted
Load multiple text files with same name but in different folders
You are right to question your current approach. With 9 sets of data with 5 repeats of each, you would need 45 variables with your current approach. Using a list or dictionary for one dimension woul …
15
votes
The car plate problem: generate from AAA0001 to ZZZ9999 skipping the 0000
You are using a sledge-hammer to crack a peanut.
Consider String[] splittedLetters = letters.split("");. The split() function takes a regular expression, so you are using the entire regular expressi …
5
votes
Accepted
Express a number as a sum of powers of 2
It is probably cheating, but the bin(x) function would do most of the heavy lifting, converting x into a string of bits. Iterate in the reverse direction (via [::-1]) to match bits with their proper …
5
votes
Accepted
print 10x10 random numbers from 1 to 3 table
Multiple lines
First off, don't try to do everything on one line. This line is doing way too much:
x = str(np.reshape([random.randint(1, 3) for i in range(100)], (-1, 10)).tolist()).replace("[", ""). …
11
votes
Accepted
Printing Pascal’s triangle for n number of rows in Python
One issue with your approach is your memory usage is \$O(n^2)\$. You are building up the entire Pascal's Triangle, and subsequently printing it. If you simply want to print Pascal's Triangle, you do …
2
votes
Looking for a more efficient algorithm for the sum of list of lists
Bugs
Mutable reference
The constructor takes an iterable of iterables, validates the type & shape, and stores that reference. If the source is mutated, the shape of the array can become invalid.
x = …
4
votes
ProjectEuler.net problem #50, Consecutive Prime Sum
Prime Generation
As mentioned by vnp, use the Sieve of Eratosthenes. In that implementation, use a BitSet(1_000_000) for efficient memory usage during your sieve; a sieve for primes up to one million …
4
votes
Encode and decode string as base-32 number
Base-32 to Integer
Enumerate
Your loop ...
_sum = 0
_pow = 0
for o in string:
if o in alpha_to_num:
index = alpha_to_num[o]
else:
index = 31
…
2
votes
Circular Buffer
Modulo arithmetic might be expensive. Consider replacing:
buf->tailOffset = (buf->tailOffset + 1) % buf->numElements;
with something more along the form of:
if (++buf->tailOffset == buf->numEleme …
3
votes
Accepted
Dijkstra's Algorithm + an additional cost to start at each node
Code Review
While I understand you're looking for performance improvements,
this is Code Review, so let's start with seeing if we can improve
the code first -- including minor performance improvements …