Questions tagged [performance]

Performance is a subset of Optimization: performance is the goal when you want the execution time of your program or routine to be optimal.

Filter by
Sorted by
Tagged with
9
votes
2answers
3k views

Finding longest substring containing k distinct characters

Below is my method to find the longest substring having k distinct characters. I have used Set to keep track of distinct ...
9
votes
1answer
166 views

Population dynamic simulation on biological information maintenance

Background Using this simulation I investigate a system in which enzymes proliferate in cells. During the replications of enzymes, parasites can come to be due to mutation. They can drive the system ...
9
votes
2answers
642 views

Gray codes addition — Take 2

For a while, I have tried to find ways (known or new) to do stuff with Gray codes. As some of you probably know, I already tried to implement an algorithm to add two Gray codes without having to ...
9
votes
4answers
2k views

Algorithm for dividing a number into largest “power of two” buckets?

For example, these are expected outputs: 3: 2, 1 4: 4 5: 4, 1 6: 4, 2 7: 4, 2, 1 8: 8 9: 8, 1 ... 20: 16, 4 ... 25: 16, 8, 1 ... 36: 32, 4 ... 50: 32, 16, 2 Up to ...
9
votes
2answers
3k views

Mandelbrot fractal with MPI

I'm not very familiar with MPI. I've written this little piece of code to draw the Mandelbrot fractal processing each row of the image in parallel. It works but it's really slow. I've written code to ...
8
votes
2answers
604 views

General Game Loop

I have two interfaces. Entity for updates. Drawable for rendering. They both have two interface methods. One that is called every frame, one every second. Entity....
8
votes
2answers
3k views

Color substitution in a BufferedImage

The setPixelColor function below changes the color of pixels. I need some suggestions to optimize this function. Example: ...
8
votes
3answers
5k views

Multi-tiered sorting using custom IComparer

I have this custom IComparer I use to sort a list of SurveyResponse objects, but it seems really inefficient, both in terms of ...
8
votes
2answers
959 views

Epidemic simulation

The purpose of this code is to simulate epidemics across a population. There are 625 (pop) individuals at random locations. The epidemic parameters are infectious period (inf_period), trans (...
8
votes
1answer
3k views

Project Euler 407: Is there any more optimal way to solve this idempotent equation (modulo n ring)?

Project Euler problem 407: If we calculate a2 mod 6 for 0 ≤ a ≤ 5 we get: 0, 1, 4, 3, 4, 1. The largest value of a such that a2 mod 6 = a is 4. Let's call M(n) the largest value of a < n ...
8
votes
3answers
16k views

Printing an hourglass pattern

In a recent interview I have been asked to write a program to generate the following output: ...
8
votes
1answer
238 views

Simulating image transfer over noisy channel with a repetition code

I need to write a software in JAVA which allows me to simulate the transfer of some images over a noisy channel while adding redundancy with a repetition code . Before going into code details and ...
8
votes
2answers
213 views

Minimum number of coins problem using dynamic programming - follow up

I previously posted a code here. It turns out that the code is not following the correct dynamic programming principles and instead it was based on a greedy approach. Hence, I started again, keeping ...
7
votes
1answer
237 views

Check consistency of a list of statements, with fuzzy rhyme matching

I made a program today that solves the following problem on a programming competition site (open.kattis.com): Check if all statements with the following format X is Y or X not Y are consistent. X and ...
7
votes
1answer
271 views

Is my LoginView class valid?

I know the Model, Controller and View's purpose, but I have never really found a good concrete class example of a View class. Usually I see people having some small ...
7
votes
1answer
22k views

Accessing an unordered_map

How can I improve the access time to this unordered map? If I instead allocate a 8 x 10 x 30 x 30 x 24000: ...
7
votes
2answers
388 views

Game of Fifteen - A Sliding Puzzle Game

Update: I addressed the changes and created an updated post. I'm reviewing C by working through the edX CS50 problem sets. This task was to implement Game of Fifteen aka 15 Puzzle. Project details ...
7
votes
1answer
2k views

Finding and pasting images into a specific cell

The below macro finds and pastes images into column A. While the macro works, it starts to slow down when running 500+ images. I am not too familiar with the VBA language, does anyone have any ...
7
votes
2answers
2k views

3Sum implementation

I have recently started to work through the problems on Leetcode, for the sake of bettering my own skills as well as preparing for interviews. I was faced with the 3Sum problem which is: Given an ...
7
votes
2answers
1k views

Homemade Stopwatch class

Here's some explanation for accuracy and neg_accuracy: It's meant to keep all the values in terms of what the user specified he ...
7
votes
2answers
16k views

Using SendAsync to send multiple emails

My method for sending emails with Send() is getting very slow when I send more than ten messages. Sample 1 (1 sec) 2 (2 sec) 3 (4 sec) 4 (8 sec) and so on... so I ...
7
votes
1answer
11k views

“Histogram of Oriented Gradients” (HOG) feature detector for computer vision

Here is a function that I've only slightly modified from its original context, found here. Before mentioning anything else, it should be noted that I'm desperately trying to optimize this code for ...
6
votes
1answer
374 views

Fast prime generator

I wanted to test my performance optimizing skills, and so wanted to find how fast I could get the first \$n\$ prime numbers. I limited myself to only the standard library, as I'm sure ...
6
votes
2answers
3k views

Prime factorization for integers with up to 9-digit long prime factors

I've become interested prime factorization since solving Project Euler problem 3 (finding the largest prime factor of 600851475143). Learning here that initializing lists with many elements to later ...
6
votes
3answers
869 views

Split large file into smaller files, keeping headers and footers

I have a folder of SQL files which I need to loop through and: Determine if any of the files are over 20MB If so, split them into multiple files, max 20MB filesize However, there's a complication ...
6
votes
3answers
220 views

Custom integer parser optimized for performance

I want an integer parser so fast it risks discovering time travel. I'm stuck in C# for a language, but that doesn't mean I can't try to use c++. So I wrote the following: The best I could do ...
6
votes
1answer
4k views

A simple MP3 player with React.js

I've been learning React.js for the last few days and am working on a simple MP3 player. I have a few years experience with JavaScript, however, I am just trying to get used to the idea of components ...
6
votes
2answers
6k views

Convert Roman to Int

I made a function that converts Roman letters to integers. But I'm not happy with it, as I feel like I used too much code for a such a simple task. Any suggestion on how I can minimize it? ...
6
votes
1answer
340 views

Recursive implementation of merge sort

Information about my code: I am following this MIT OCW algorithms course. The first lecture described insertion sort and merge sort. I implemented merge sort in C. The algorithm is structured as a ...
6
votes
3answers
5k views

Executing a URL using RestTemplate

I am working on a project in which I construct a URL with a valid hostname (but not a blocked hostname) and then execute that URL using RestTemplate from my main ...
6
votes
6answers
7k views

Project Euler #10 — Summation of primes takes forever

I have resolved the Problem presented in Project Euler #10: The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two million. But this code takes too long ...
6
votes
2answers
2k views

Beginner word-guessing game

The aim is to guess a four letter string. Each letter can be tried four times. If the letter cannot be guessed, we go to the next letter until the fourth letter is reached. I looked at my code and ...
6
votes
1answer
314 views

Sieve of Eratosthenes for prime generation

I was originally going to write this intro as just being the bare-bones "here's my problem, here are some ideas, what do you recommend" format (which I am still going to follow, mind you), but I've ...
6
votes
3answers
167 views

Finding the longest word without these characters

My goal is to go through the list of all English words (separated by '\n' characters) and find the longest word which doesn't have any of these characters: ...
6
votes
3answers
345 views

Calculating time windows for entities

I have made some code that operates on multiple entities and creates 'time windows' for them. Basically, the entities will contain states, usually in boolean or int. They will be timestamped and in ...
6
votes
3answers
235 views

Class scheduling tool with image output

I have a multilayered dictionary that contains information about classes. I am using this to code an automatic schedule builder that I will eventually add to a separate Tkinter application I made that ...
5
votes
1answer
471 views

Josephus permutation

This problem is taken from the book Introduction to Algorithms, Third Edition By Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest and Clifford Stein: We define the Josephus problem as ...
5
votes
3answers
842 views

Project Euler 38: Pandigital Multiples

I just solved Project Euler 38 and was wondering if you guys could provide some suggestions on how to speed it up. I've tried adding extra conditions but they increase the time. Any ideas on how to ...
5
votes
2answers
5k views

Mars Rover Simulator

Problem Statement Consider a rover and a plateau of size nxn. The rover takes three type of instructions L,R and M. 'L' and 'R' rotate the rover in the left and right direction. 'M' moves the ...
5
votes
1answer
90 views

UTF8 Codepoint decode and length v.2

This is the complete rewrite of a function to decode an UTF-8 codepoints and return the encoding length (or 0 if the codepoint is ...
5
votes
2answers
1k views

HackerEarth Girlfriend's Demand challenge, solved two ways

I solved the Girlfriend's Demand challenge on HackerEarth. In summary: Input: First line of the input contains a string S. Next line contains an integer Q, the number of queries. Each of the next ...
5
votes
4answers
7k views

Data type detection for a CSV file parser

I am building a CSV file parser, and in order to get the appropriate Object to represent different data types found on the parsed files, I wrote the following function: ...
5
votes
1answer
3k views

Sieve of Eratosthenes in Python 3

Currently, the code will generate a range of natural numbers from 1 to N and store it in a list. Then the program will iterate through that list, marking each multiple of a prime as 0 and storing each ...
5
votes
2answers
369 views

Getting list of daily team goals

The old code I had before was atrociously slow but after some advice and research I was able to take a 2-5 minutes run time down to about 5-30 seconds. That is acceptable, but still looking to have ...
5
votes
1answer
8k views

Substring vs Split performance test

Some people are telling me that using string.Split is very inefficient since it creates a lot of arrays in the heap. So, what are the alternatives if its real? The challenge? Taking a large string ...
5
votes
2answers
3k views

Function that normalizes a vector of double

I have written the following function in order to normalize a container of double, so that it sums up to 1.0: ...
5
votes
1answer
4k views

Project Euler Problem 12 - Highly Divisible Triangular Number - Python Solution Optimization

Project Euler Problem 12 asks (paraphrased): Considering triangular numbers Tn = 1 + 2 + 3 + … + n, what is the first Tn with over 500 divisors? (For example, T7 = 28 has six divisors: 1, 2, 4, 7, ...
5
votes
1answer
2k views

WAVE to FLAC encoder in C

This is a .wav to .flac encoder that I wrote a little while ago. The only method that is really called is ...
5
votes
1answer
1k views

2D Perlin noise generaton needs Perfomance

I'm trying to use a Perlin noise generator to make the tiles of a map, but I think the code is too slow, I mean, I took some hours to complete the generation of 1000 x 1000 chart. (I didn't used ...
5
votes
2answers
3k views

Project Euler problem 92 - square digit chains

Link to problem. A number chain is created by continuously adding the square of the digits in a number to form a new number until it has been seen before. For example, 44 -> 32 -> 13 -> ...

1
3 4
5
6 7
12