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
21
votes
10answers
5k views

Palindromes in C

The function tests whether or not the provided string is a palindrome, and the main function just times how quick it is (after all, C's supposed to be quick, right?)...
20
votes
2answers
6k views

String reversal in Python

This code will take as output any string (long, empty, with spaces...) and will return its reverse. Can I improve this algorithm so that it can be faster? Right now its complexity is \$O(n)\$. <...
15
votes
3answers
12k 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 ...
15
votes
1answer
12k views

Rotating greyscale images

For educational purposes I wrote a little piece of code to rotate greyscale images as "low level" as possible, that is, not using any rotate() function, but doing ...
14
votes
7answers
27k views

Checking if two strings are an anagram

This is my sample code to check if a given pair of strings are anagram or not. ...
14
votes
4answers
3k views

2-sum problem on a range in Python

Here is the problem description (from an algorithm course: https://www.coursera.org/learn/algorithm-design-analysis): The goal of this problem is to implement a variant of the 2-SUM algorithm (...
12
votes
2answers
5k views

Generating 'Decent' numbers

While solving a problem from HackerRank, though it's an easy one, I wrote this big program. Not sure if recursion is applicable and hold good but to me it looked like it isn't. However when I run the ...
12
votes
7answers
6k views

Is this a fast implementation of reversing a string?

I thought of this algorithm today. It seems fast, but how can I know? ...
12
votes
3answers
3k views

Codewars: Reduce strings to one character

I am trying to solve a puzzle in a performant way. This is the puzzle. Simply explained: you have a String and you must reduce it to one character with the given rules. This is the solution to the ...
12
votes
2answers
8k views

C++ vector implementation

I have tried to implement a basic vector type in C++, yet I am not sure if I can do anything any more efficiently. ...
11
votes
1answer
628 views

Copy, Paste And Format

I am currently working with this code to automate some tasks for senior staff members that are not very adept in Excel. Wondering if VBA is simply not a very quick code or if my code is clunky and ...
11
votes
5answers
3k views

Finding count of character occurrences in a string

I am taking an introductory course in java in high school, however I have some experience in python. I was tasked to find the number of times a character occurs in a string so I did this. ...
10
votes
1answer
247 views

Science Fiction Wall of Fame (Shame?)

I have a few of hobbies, one is reading science fiction and fantasy and another is coding solutions. I thought I might have a chance to combine both hobbies on this project. I have well over 1500 ...
10
votes
2answers
391 views

Naive implementation of KMP algorithm

After reading this answer to the question "High execution time to count overlapping substrings", I decided to implement the suggested Knuth-Morris-Pratt (KMP) algorithm. I used the pseudo-code listed ...
10
votes
1answer
706 views

Let's read a random Goodreads book in an optimal way

I have made the following program to gather data on random books from Goodreads, via their random books feature. ...
10
votes
2answers
414 views

Scoring and grading answers against an answer key

This is for a university assignment (don't worry the code is in working order), and while I could hand it in as-is and receive full marks I feel like there is probably a more efficient and better way ...
9
votes
4answers
6k views

Convert IP address to its binary representation

For a recent lab at the university we had to match the longest prefix for an IP (v4) address by using a Trie data structure. The code works fine, but it takes about 2 minutes to load a 14 million-line ...
8
votes
1answer
4k views

Find the nearest point of a given set of points

Suppose there are a set of given points (represented by x and y two dimensional coordinates), and for any given point A, I want ...
8
votes
4answers
5k views

Calculating the factorial of a number efficiently

I was trying to calculate the factorial of a large number in a short time: ...
8
votes
1answer
830 views

Prefix trees for auto suggest

I wrote a quick prefix tree implementation. I know it may be far from perfect, but I need to make sure that I got the basics right. My main concerns are: Have I settled for the correct data ...
7
votes
1answer
2k views

General Game Loop 2.0

Follow up from General Game Loop I have two interfaces. Entity for ticks. Drawable for rendering. Drawable.java ...
7
votes
3answers
2k views

Retrieve value from a formula in cells into different merged cells and retrieved value can be edited

I have created this macro and having a small issue. I am very new to this VBA and did this with experts’ guides by googling it. I am creating an excel form for a work purpose at work. The Excel form ...
7
votes
2answers
121 views

Put it in a bucket

You're running a jeans company. Your system is collecting detailed orders' data, but it's a bit archaic and it's storing the number of units ordered per size in a delimited string with 20 "fields", ...
6
votes
3answers
9k views

Project Euler #13: Large Sum

Description: Work out the first ten digits of the sum of the following one-hundred 50-digit numbers. ... Of course I didn't include the numbers in the description... I am sure there is a better ...
6
votes
1answer
790 views

Optimizing breadth-first-search code

I wrote code using some kind of breadth-first-search algorithm in order to find a path (any path!) from a start point to an end point. There are no weights/different distances involved from path-to ...
5
votes
1answer
6k views

Finding missing items in an int list

Here is a problem I am trying to solve: trying to find missing photographs from a sequence of filenames. The problem boils down to: given an unsorted list of integers, return a sorted list of missing ...
5
votes
3answers
1k views

Binary Search in C - Optimization

I know that there is a function bsearch present in stdlib.h but still I want to implement this. This is my code for binary ...
4
votes
1answer
772 views

Insertion Sort implementation in Java

I have implemented Insertion sort in Java. Please review it. ...
4
votes
1answer
175 views

Calculate the Euler-Mascheroni constant without the math module

The below code was written to generate γ, for educational purposes. Single threaded, no functional zeroes required, no binary splitting(which can all be used to compute competitively like y-cruncher, ...
3
votes
0answers
686 views

Efficiently writing string comparison functions in Python

Let's say I work for a company that hands out different types of loans. We are getting our loan information from from a big data mart from which I need to calculate some additional things to calculate ...
3
votes
1answer
1k views

Inversion count via divide and conquer

I'm happy to hear thoughts and ideas on structure/performance/testing/whatever and multi-threading, which I haven't gotten into yet with Python. Full code here. Assignment file and a test file ...
2
votes
2answers
4k views

Simulation of 2D elastic balls

Following this SO post and this Wikipedia article, I wrote a Python script to simulate physics of 2D elastic balls. I define the physical behaviour of each ball in the ...
2
votes
0answers
55 views

Performance of a jQuery module

Following this question, I've rewritten my module as follows: ...
2
votes
1answer
3k views

Approximating/Sorting groups of dates into buckets

I'm working on a directed study project with a professor of mine helping him build out a Django based website. The website is a historical account of the people, events, projects, and organization in ...
2
votes
1answer
1k views

Simple multi-dimensional Array class in C++11 - follow-up

Last week, I posted this question in order to get some comments and critiques on a simple implementation of a multidimensional array class -- hyper_array::array ...
25
votes
3answers
1k views

Gray codes addition

As some of you know, I have been working with Gray codes and am trying to design a good gray_code class in modern C++. I will end up posting several parts of the ...
25
votes
5answers
1k 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 106 ...
13
votes
1answer
266 views

Population dynamic simulation on biological information maintenance 2

This question is the follow-up to this previous question. Background Using this simulation I investigate a system in which enzymes proliferate in cells. During the replications of enzymes, ...
13
votes
3answers
2k views

Inefficient differential converter

Following Pimgd's question, I decided to take a look at the TIS-100 myself. This is my solution to the 3rd challenge, building a differential converter. Requirements: Read values from IN.A and IN....
12
votes
2answers
932 views

Speech Recognition Part 1: Generate Training Data

You've all heard of neural nets, no? One of the "hello world"s of neural nets is OCR with the MNIST dataset. My idea for speech recognition is to train the neural net with short labeled spectrograms ...
12
votes
1answer
443 views

2D Gravity Simulator-like game

This project is pretty much like a 2D gravity simulator. You click and it creates a circle that attracts other circles. The result of a collision is a bigger circle that is a sum of the masses. If you ...
11
votes
2answers
509 views

SimCity clone performance

I am working on a SimCity clone, and I am noticing a drop in frame rate as I add more objects to my map, now this is expected, but, when I fill the whole screen, the game maintains about 300 FPS. ...
11
votes
4answers
7k views

My own SHA-256 code implementation

I'm worried about my code performance. The code I've written is an implementation of SHA-256 using pseudocode from Wikipedia. It works fine, but I want to speed it up. With a buffer of 4096 bytes, I ...
10
votes
2answers
203 views

Simulation of image transfer over noisy channel

Following this question, I've tried to rewrite some core methods to avoid using String for bit operations, and I ended up using ...
10
votes
3answers
3k views

Poker Hand Evaluation - Finding a straight

Weekend Challenge #2 - Poker Hand Evaluation Finding a straight with wildcards Because of a size limit on Code Review I have to split my weekly challenge result in two, and here is a part where I ...
10
votes
2answers
708 views

Swift replacement for C's for-loop

I recently wrote an entry on my blog regarding unit testing using prime numbers as an example. When I wrote the entry, I wrote my code keeping in minding that proposal SE-0007 has been accepted for ...
10
votes
1answer
244 views

Civilization 5 mod validator

I would like to submit a portion of my code for Code Review, and I have done my best to comment the code (and include essential parts that may aid understanding of the program) for your convenience! ...
10
votes
2answers
1k views

Using 2D arrays to make more efficient sequential storage

This code is part of a growing "primitive" tools collection here on github Use Case Consider: ...
10
votes
2answers
566 views

Simple parser using Flex and C++

This is an alternative parser based on the specifications from this question. Briefly stated, the input file is a text file which has at least 33 fields separated by semicolons. If the fourth field ...
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 ...

1 2 3
4
5
12