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
61 votes
3 answers
4k views

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 ...
Simon Forsberg's user avatar
29 votes
4 answers
7k views

Sieve of Eratosthenes - Python

I've been doing a lot of Project Euler lately and just wanted to make sure my implementation was as good as it could be. Does anyone have any suggestions to speed this up? ...
Igglyboo's user avatar
  • 447
23 votes
6 answers
14k views

Optimize 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 ...
Adam Arold's user avatar
9 votes
2 answers
270 views

Hand Coded State Driven Lexical Analyzer in C With Unit Test Part A

This code review is presented in 3 questions due to the amount of code: Part A (this question) contains the Lexical Analyzer and the main portion of the unit test code. Part B contains the lower ...
pacmaninbw's user avatar
  • 23.5k
58 votes
9 answers
14k views

Project Euler problem 1 in Python - Multiples of 3 and 5

I'd like suggestions for optimizing this brute force solution to problem 1. The algorithm currently checks every integer between 3 and 1000. I'd like to cut as many unnecessary calls to ...
Robert S Ciaccio's user avatar
12 votes
3 answers
6k views

Project Euler Problem 12 - triangle number with 500 divisors

I've just done Problem 12 of Project Euler: What is the value of the first triangle number to have over five hundred divisors? The \$N\$'th triangle number is the sum of all natural numbers ...
Connor Cartwright's user avatar
2 votes
1 answer
151 views

A recursive_transform Template Function with Execution Policy

This is a follow-up question for A recursive_transform for std::vector with various return type, A recursive_transform Function For Various Type Nested Iterable With std::variant Implementation in C++ ...
JimmyHu's user avatar
  • 3,984
38 votes
6 answers
6k views

Parser written in PHP is 5.6x faster than the same C++ program in a similar test (g++ 4.8.5)

I'm absolutely dumbfounded by this. I was trying to demonstrate to myself how much faster C++ is than even modern PHP. I ran a simple CSV parsing program in both that have the same output. The CSV ...
Luke's user avatar
  • 481
37 votes
9 answers
79k views

Using a for-loop or sleeping to wait for short intervals of time

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 ...
Mohammad's user avatar
  • 1,212
33 votes
6 answers
65k views

Brute Force Algorithm in C

This is a simple brute force algorithm that I have programmed in C. All the program does is print out every possible combination of the given alphabet for the ...
syb0rg's user avatar
  • 21.8k
14 votes
1 answer
9k views

Solving 15 puzzle

I'm trying to solve 15 puzzle using A* algorithm, but something really bad goes on in my get_solution() function that ruins performance. I guess there is a too much ...
Tikhon Belousko's user avatar
10 votes
4 answers
27k views

Find the binary gap of a number N

For example, number 9 has binary representation 1001 and contains a binary gap of length 2. The number 529 has binary representation 1000010001 and contains two binary gaps: one of length 4 and one of ...
Cormack's user avatar
  • 191
9 votes
2 answers
10k views

How can I quickly find unique list items?

I use the loop-every-single-list-item approach to filter out unique elements in a given list, which tends to be very inefficient way as a list grow in size, or as function call frequency increases. ...
Nikola Vukovic's user avatar
7 votes
3 answers
3k views

Efficiency of Project Euler problem 35

The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime. There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, ...
yask's user avatar
  • 245
6 votes
1 answer
981 views

Recursive Breadth First Search for Knights Tour

This was written as an experiment in performance, based on another question here on CodeReview. Input into the algorithm is the number of squares on one edge of the chess board, the point of origin, ...
pacmaninbw's user avatar
  • 23.5k
5 votes
1 answer
306 views

Knights Tour - Improved Refactored Recursive Breadth First Search for

The development and testing was performed on a Dell M6400 Laptop (Intel Core 2 Duo) running Centos 7, g++ compiler version 4.8.5, compiler switches -O3 -std=c++0x -D__cplusplus=201103L. (machine ...
pacmaninbw's user avatar
  • 23.5k
5 votes
1 answer
89 views

Hand Coded State Driven Lexical Analyzer in C With Unit Test Part C

This review is presented in 3 questions due to the amount of code: Part A contains the Lexical Analyzer and the main portion of the unit test code. Part B contains the lower level unit tests called ...
pacmaninbw's user avatar
  • 23.5k
2 votes
1 answer
103 views

A recursive_transform Template Function Implementation with std::invocable Concept and Execution Policy in C++

This is a follow-up question for A recursive_transform Template Function Implementation with std::invocable concept in C++ and A recursive_transform Template ...
JimmyHu's user avatar
  • 3,984
21 votes
4 answers
2k views

Finding the sub-array with the maximum sum - my approach

This is the code I ended up with that implements the approach I described in a recent answer to another question about the same problem The basic idea here is to not loop through more things than ...
Simon Forsberg's user avatar
13 votes
3 answers
5k views

The Beauty and the Strings

This originally appeared in Facebook's hacker cup 2013. Solving it was fun, though I find myself looping through similar data quite often. Challenge: Print the maximum beauty of strings. ...
Legato's user avatar
  • 9,819
11 votes
1 answer
501 views

Sequence-based enumeration of permutations in lexicographic order

This is follow-up on On Knuth's "Algorithm L" to generate permutations in lexicographic order, where I presented the following method to enumerate all permutations of array elements in ...
Martin R's user avatar
  • 23.1k
11 votes
3 answers
3k views

Coin Change: Minimum number of coins

Problem: You are given n types of coin denominations of values \$v(1) < v(2) < ... < v(n)\$ (all integers). Assume \$v(1) = 1\$, so you can always make change for any amount of money \$C\$....
CyberLingo's user avatar
11 votes
2 answers
569 views

A Specific Combination

This code is going to be included in my Minesweeper Probabilities project. (so far it only exists on the develop-branch) The purpose is to return a specific combination, let's say for example that ...
Simon Forsberg's user avatar
8 votes
1 answer
1k views

Timing analysis of many test cases in Python

I am learning about timing analysis in Python. I used time module before it was pointed out that timeit module would be better ...
Aseem Bansal's user avatar
  • 2,259
7 votes
4 answers
621 views

MergeSort performance

Do you see any inefficient parts with the following code? On internet I see 30 ms for 100.000 integers but I can sort 100.000 integers in 300ms. The data is random. I am using late 2013 macbook pro so ...
EralpB's user avatar
  • 173
6 votes
4 answers
625 views

Class Seperation vs Polymorphism

I'm interested in optimizing my code. Can someone help me understand the best way to trim this code down with DRY methodology? So I've got these two classes here preforming WMI queries on two ...
Gabriel W's user avatar
  • 371
5 votes
2 answers
906 views

Matrix of articles and authors from large JSON dataset

Given the following JSON data containing 4 articles by 4 different authors: ...
CodeYogi's user avatar
  • 5,087
5 votes
2 answers
3k views

Generating frequency tables based on CSV dataset

I am working on a project which crunches plain text files (.lst). The name of the file names (fileName) are important because I'...
Bram Vanroy's user avatar
5 votes
2 answers
9k views

Printing longest sequence of zeroes

I am doing a coding exercise in codility and I came across this question: A binary gap within a positive integer N is any maximal sequence of consecutive zeros that is surrounded by ones at both ...
would_like_to_be_anon's user avatar
4 votes
1 answer
2k views

Simplifying and optimizing factors and prime factorization generator

My first algorithm for finding the factors of a number was pretty slow and horrible (it started at \$O(n^2)\$, where n was not even the inputted number), but I eventually came up with this new code. ...
Jamal's user avatar
  • 34.9k
4 votes
1 answer
62 views

Hand Coded State Driven Lexical Analyzer in C With Unit Test Part B

This review is presented in 3 questions due to the amount of code: Part A contains the Lexical Analyzer and the main portion of the unit test code. Part B (this question) contains the lower level ...
pacmaninbw's user avatar
  • 23.5k
4 votes
1 answer
257 views

Simple neural-network simulation in C++ (Round 2)

Intro Yesterday I posted this question. Since then, I've updated my code to incorporate these suggestions. I've also removed the dependence on C++11. Finally, I've made the following changes that ...
abcd's user avatar
  • 329
3 votes
2 answers
2k views

Non generic Skip List implementation in C++ Version 2

Edit: This code was reworked and repostetd under a new question: Generic Skip list implementation in C++ Version 3 This is a follow up of: Non generic Skip List implementation in C++ If you don't ...
Sandro4912's user avatar
  • 3,046
3 votes
2 answers
119 views

C# Tool to Generate MS Word Document Mailbox List From MS Excel

There is now a Follow up question to this question. Abstract The VBA solution didn't work on the clients computer because Office 2010 Starter Edition doesn't support VBA. I decided to try a C# ...
pacmaninbw's user avatar
  • 23.5k
3 votes
1 answer
422 views

A rather accurate VBA stopwatch

Intro Related, related I'm trying to come up with a neat, accurate way of timing VBA code, as I'm yet to find a method to do this in VBA directly (without plugins etc.) The general idea was to ...
Greedo's user avatar
  • 2,345
3 votes
2 answers
105 views

Mixed Duo String Generator

I've create a program that finds mixed duo within a string. It removes characters from a string that do not form the first mixed duo. It does not rearrange the order of the string, it ony remove ...
Laurent's user avatar
  • 89
3 votes
2 answers
1k views

Premium palindromic primes

Challenge: Write a program which determines the largest prime palindrome less than 1000. The answer is 929, and my program correctly finds and prints this, but actually ended up being more complex ...
Legato's user avatar
  • 9,819
2 votes
1 answer
1k views

Fast Prime Sieve (Python Implementation)

A modified version of the prime sieve. I actually doubt it could be implemented any faster, but I might be wrong: ...
Tobi Alafin's user avatar
  • 1,806
2 votes
1 answer
50 views

Find perfect and amicable numbers

I've been playing with perfect, amicable and social numbers lately, and created a class for investigating these. At present, it has functions to return the perfect and amicable numbers in a specified ...
Toby Speight's user avatar
2 votes
2 answers
92 views

Common Unit Testing Code – Follow Up

This question is a follow up question to the Common Unit Testing Code portion of my lexical analyzer questions. My primary concern is the code in the header file and the C source file that implements ...
pacmaninbw's user avatar
  • 23.5k
34 votes
4 answers
19k views

Recording audio in C

Please note there are newer revisions of this code, one here, and one here for continuous audio recording. This is a program I wrote as a .wav audio recording library for Linux. It was developed on ...
syb0rg's user avatar
  • 21.8k
33 votes
7 answers
6k views

Project Euler #7 10001st prime

I decided to start working on the Euler project exercises. I'm doing fine for now but the seventh problem is running quite slow and I can't think of anything to make it work faster. It takes around ...
Denis's user avatar
  • 8,448
29 votes
6 answers
4k views

DailyProgrammer 284: Wandering Fingers

Description Software like Swype and SwiftKey lets smartphone users enter text by dragging their finger over the on-screen keyboard, rather than tapping on each letter. You'll be given ...
px06's user avatar
  • 393
26 votes
4 answers
4k views

Poor man's JIT using nested lambdas

While answering this code review question, I came up with a way to convert an equation given at runtime to a std::function<double(double)> that would evaluate ...
G. Sliepen's user avatar
  • 50.4k
26 votes
3 answers
124k views

Brute force password-cracker

I am just coding some classic brute force password cracking program, just to improve myself. I've explained how my program works at the start of the code. Check some of those screenshots to ...
user avatar
24 votes
2 answers
2k views

parcel: a JSON parsing library in C

I've created a JSON parsing library in C, and would like some feedback on it (feel free to submit a pull request on GitHub). Any and all suggestions are acceptable, but I would prefer if reviews were ...
syb0rg's user avatar
  • 21.8k
20 votes
5 answers
3k views

Print the N longest lines in a file

I have implemented the "Find the N longest lines in a file" problem from CodeEval quoted below. I got a full 100 score and 182ms execution time of their data set on the site so I consider the code ...
Emily L.'s user avatar
  • 16.5k
18 votes
5 answers
5k views

Printing a list as "a, b, c." using Python

Is there a better way to do this? Assuming very long lists, is this slow and wasteful? ...
jeremy radcliff's user avatar
16 votes
3 answers
4k views

On Knuth's "Algorithm L" to generate permutations in lexicographic order

I needed a method to generate all permutations of given elements, so I decided to implement "Algorithm L (Lexicographic permutation generation)" from Donald E. Knuth, "GENERATING ALL PERMUTATIONS" in ...
Martin R's user avatar
  • 23.1k
16 votes
3 answers
1k views

Wheel based unbounded sieve of Eratosthenes in Python

Answering this SO question recently, I've developed the following code (based on a well-known Active Code recipe, as discussed here): ...
Will Ness's user avatar
  • 1,006

1
2 3 4 5
14