Tagged Questions
Performance is a subset of Optimization: performance is the goal when you want the execution time of your program or routine to be optimal.
41
votes
8answers
9k views
Fastest way to clamp an integer to the range 0-255
I'm working on some image processing code that can generate pixel values outside of the normal range of 0 to 255, and I'd like to clamp them back into the valid range. I know that there are saturating ...
20
votes
1answer
645 views
How can I make my stack monad faster?
I made a stack monad that lets one manipulate and control values on a stack.
I want to know if it's correct (it seems correct), how to make it faster, and how I could detect stack overflows without ...
19
votes
7answers
2k views
Using a for-loop instead of sleeping?
I need to wait for short intervals of time in my program, but I really don't want to include unistd.h just to use sleep, so I'm ...
18
votes
3answers
264 views
+150
Analyzing Minesweeper Probabilities
Calculating probabilities in Minesweeper might sound like an easy task, but I've seen so many probability calculators that's either incorrect, horribly slow, or with ugly code (or all of them) so I ...
17
votes
6answers
5k views
Why is my C# program slower than my Python program?
I made a program in Python and wanted it to be faster, so I wrote it on C# because it's compiled. To my surprise, the Python program is much faster. I guess there is something wrong with my C# code, ...
17
votes
5answers
843 views
Count distinct primes, discarding palindromes, in under 2 seconds
Problem Statement
Generate as many distinct primes P such that reverse (P) is also prime
and is not equal to P.
Output:
Print per line one integer( ≤ 1015 ). Don't print more than
...
17
votes
1answer
1k views
Improving the Java UUID class performance
I am looking to submit the following code (adapted to fit into java.util obviously) which significantly improves performance and reduces useless allocations of ...
16
votes
4answers
2k views
Regex to parse semicolon-delimited fields is too slow
I have a file with just 3500 lines like these:
filecontent= "13P397;Fotostuff;t;IBM;IBM lalala 123|IBM lalala 1234;28.000 things;;IBMlalala123|IBMlalala1234"
...
15
votes
7answers
6k views
Optimizing List<string> performance
I have a List<string> being stored in my cache with about 600K members. I want this to act as the backend for an Ajax autocomplete box. It's accessible ...
15
votes
3answers
2k views
Int overflow check in Java
I have a piece of code that takes a couple of integers and check if performing an addition on the inputs would result in an overflow.
I was wondering if this code is SOLID:
...
14
votes
6answers
2k views
Sherlock and The Beast
This is my solution to this question from Hackerrank.
Given N (<= 100000), find the largest N-digit number such that:
The number has only 3 and 5 as its digits.
Number of times 3 ...
14
votes
3answers
593 views
Planetary Nomenclature
I'm new when it comes to Java and programming in general, but I feel I have a decent grasp on a lot of the fundamentals.
I've created this "random planet generator" that is virtually useless aside ...
14
votes
3answers
7k views
Reusing StringBuilder or creating a new one?
Given that it is better to reuse objects than create new ones when developing with Android, is it worth while deleting the contents of a StringBuilder and reusing ...
13
votes
2answers
655 views
Speed up solution to Project Euler problem 75
I've been programming for a few months now, and have used Stack Overflow a great deal, but this is my first post. Anyway, I wrote this code for Project Euler problem 75, which asks how many integers ≤ ...
12
votes
3answers
2k views
Finding pair of sum in sorted array
In a sorted array, I am trying to find pairs that sum up to a certain value. I was wondering if anyone could help me improve my code in performance or memory. I believe my code is O(n). If there are ...
12
votes
2answers
381 views
Attempt at a sorting algorithm
I've been playing around and reading up on some sorting algorithms, and I've decided to try writing my own. It turned out to be quite fast (compared to the others shown in the image below).
I'm very ...
12
votes
1answer
106 views
Temperature Interpolation
I want to interpolate temperature in correlation with height. I have temperature data from stations with coordinates and height in this format:
...
11
votes
4answers
1k views
What would be preferred aesthetically and performance wise?
Which one of these two would you prefer writing in your code?
This:
...
11
votes
3answers
413 views
Printing the most used words from phrases
I have a collection of phrases in a List. Each phrase is a String Array where each element in the array is a word.
I create a ...
11
votes
3answers
373 views
Text “analyzer” in C++
I have few years of experience with web and I recently started learning C++ and I feel a bit lost, so I would like to ask to for some tips how to improve my code overall. This text summarizer should ...
11
votes
2answers
821 views
First prime number larger than given integer
How can I test this C program for "efficiency"? The most interesting usage is that it returns negative output for large enough input, otherwise the behavior is about expected. Will you suggest how to ...
11
votes
2answers
286 views
Division without / operator
I created a method that does division without the / operator. I believe this code is a bit slow and can be improved, but I am not sure how to do so. I'm not so good ...
11
votes
3answers
256 views
Pi Benchmarking in C
I wrote the following program to calculate n digits of Pi (where n could be anything, like 10M) in order to benchmark the CPU and it works perfectly (without OpenMP):
...
11
votes
4answers
311 views
Why is this code so much faster (relatively) in IE7?
Here's some code that I ran through jsperf to assess its performance. The first test (named EvalLengthBefore++ in the images below) is the way I would consider normally looping through the elements of ...
11
votes
2answers
9k views
Integer to Alphabet string (“A”, “B”, …“Z”, “AA”, “AB”…)
So this question is prompted by two things.
I found some code in our source control doing this sort of things.
These SO questions:
...
11
votes
3answers
213 views
Search script code efficiency
Is there a more efficient way to write this? This script will be used heavily and I want to make sure I do not have any memory leaks or speed issues.
This script gets an input from a form and ...
11
votes
1answer
290 views
Recursion vs iteration of tree structure
Some recursive code is part of a particularly slow path of a project. Out of curiosity I was playing around with reimplementing the code using stack context iteration instead of recursion. Below are ...
11
votes
4answers
3k views
Mark rows with identical values in a table
I have an simple algorithm which marks table rows with identical entries blue. The problem is that this solution takes a lot of time.
Has anyone an idea how to improve the speed of this?
...
10
votes
7answers
3k views
Reading Large Files in Java getting really slow
I am trying to read a large file ~200 MB (~300 million lines of text). I am using a relatively standard way of reading like:
...
10
votes
5answers
1k views
Conway's Game of Life
I have coded up an implementation of Conway's Game of Life and I have a performance bottleneck in it which I wish to be optimized. The main logic is in the Universe ...
10
votes
4answers
266 views
Sieve of Eratosthenes optimization
I am making a program to find primes between the given range of numbers. Unfortunately, the algorithm I created is too slow. Do you have any ideas of how to optimize the code?
...
10
votes
3answers
2k views
Brute Force Algorithm in C
This is a simple brute force algorithm I have in C. All the program does it print out every possible combination of the given alphabet for the given length.
I ...
10
votes
3answers
535 views
How to do efficient string concatenations in JS?
I form DOM nodes as strings and append them to DOM tree like below using jquery.
...
10
votes
2answers
119 views
Processing text files for data extraction and analysis
I started learning Haskell to see if I can use it at my job. A lot of my work is processing text files for data extraction and analysis.
For my first test, I added a counter at the end of each line ...
10
votes
3answers
208 views
Why is this geographic search incredibly slow?
I have this table (inradar_ad) with almost 300k entries. I want to know why my query takes 160 secs to run.
I tried limiting with ...
10
votes
2answers
356 views
Linked list arithmetic
I am practicing for interviews and I tried solving the problem on my own and got a solution. I was wondering how can I improve the performance and memory on this program?
The problem performs ...
10
votes
3answers
327 views
Enigma simulator performance
Here is my implementation of a simple 3 rotor Enigma machine in C++:
...
10
votes
2answers
116 views
Comparing client lists with Cross Joins
I've written a query to compare the clients in our database with the people in a list that I've received. It needs to check if anyone from the list is one of our clients. I've created a temporary ...
10
votes
1answer
311 views
Factoring quadratic equation
First of all, I would like to say that I am fairly new to Python and programming. I started learning Python back in September and I know that I have a ton of room for improvement, which is why I am ...
10
votes
2answers
137 views
3D mathematical vector class
I've been working on a 3D mathematical vector class which should be as streamlined as possible for use in numerical simulations. It will be used to model 3D-physical vectors.
Here, 3D-vector should ...
10
votes
1answer
149 views
Faster way to find maximum deviation?
So, it was a part of my coding challenge and the last one, but I failed because it failed to yield a result in two seconds for some of sample inputs (out of six samples, three passed but three failed ...
10
votes
2answers
506 views
“FIZZ BANG BUZZ!” 3,7,11 efficiency
I wrote a fizz buzz variation method in Python which prints "fizz", "bang", and "buzz" for 3, 7, and 11 respectively.
...
10
votes
2answers
450 views
Creating Excel document is very slow
Attached is a generic code I wrote to create an Excel file with x number of worksheets.
The problem I am having is that it's pretty slow, like 5 seconds a sheet. It was my understanding that using a ...
10
votes
2answers
111 views
Improve performance of math function applied to arrays
This block of code is already somewhat optimized thanks to some answers given over at Stack Overflow. In the last question I made (Improve performance of function without parallelization) the code was ...
10
votes
1answer
86 views
Locating matching files with input folder and file prefix
This is my first more-than-1-line script. It takes an input folder and a file prefix and gets all the matching files. For the first of the files, the script grabs the first line and appends an extra ...
10
votes
1answer
379 views
Capture with User32.dll or hook?
I am trying to capture screenshots as fast as possible from when it's displayed, meaning that I want the latency to be minimal.
Currently, I am using user32.dll to capture a window. So, if I have a ...
10
votes
1answer
125 views
Tweets per second, using linked list
This is a TalentBuddy Challenge
Your task is to
write a function that prints to the standard output (stdout) the highest number of tweets recorded between each second in the array and the past ...
10
votes
1answer
144 views
Password Manager UI: Populating DataGridView is Painfully Slow
I'm designing a small account/password manager using C# and SQL Server CE. LINQ to SQL is my ORM of choice.
Here's the data model representing how the SQL Server CE database is set up:
And here's ...
10
votes
2answers
67 views
Component-oriented implementation of JList
One of the main problems I have with JList is that no component is actually added to it. This means that things like ...
10
votes
0answers
73 views
Simplifying Python Pandas code for selecting co-occurrences in a window of time
I am a beginner at programming. I was able to build the thing below, which achieves what I want with a small dataset. With larger datasets, my RAM gets swamped bringing the computer to a halt (2014 ...