516
votes
Accepted
High throughput Fizz Buzz
x86-64+AVX2 assembly language (Linux, gcc+gas)
Build and usage instructions
This program is most conveniently built using ...
138
votes
65
votes
High throughput Fizz Buzz
After much trial and error, with the goal of not resorting to Assembly while achieving the best single-threaded performance, this is my entry:
...
46
votes
Accepted
43
votes
Fastest Mini-Flak Quine
Mini-Flak, 6851113 cycles
The program (literally)
I know most people aren't likely expecting a Mini-Flak quine to be using unprintable characters and even multi-byte characters (making the encoding ...
38
votes
High throughput Fizz Buzz
I was struggling to get more than 2.75GB/s on my rig but then I realised I wasn't compiling with -O3 which bumped me up to 6.75GB/s.
...
34
votes
Fastest yes in the west
Bash, 3 bytes, 1.9 GB/s
yes
Try it online!
Admittedly this is a troll solution, but the rules do not explicitly forbid it, and it should get you a value close ...
25
votes
23
votes
High throughput Fizz Buzz
I tweaked Neil's code a bit (so most credit goes to him) and managed to squeeze some more performance out of it; I also prepared it for unrolling more loops but ultimately I gave up (that's why the ...
22
votes
High throughput Fizz Buzz
Here is my attempt at using just-in-time compilation to emit fast FizzBuzz assembly that is specialized for every digit length. It's basically the same idea as Neil's answer, just more overengineered....
18
votes
Fastest Mini-Flak Quine
128,673,515 cycles
Try it online
Explanation
The reason that Miniflak quines are destined to be slow is Miniflak's lack of random access. To get around this I create a block of code that takes in a ...
16
votes
Accepted
Approximating a special case of the Riemann Theta function
C++
No more naive approach. Only evaluate inside the ellipsoid.
Uses the armadillo, ntl, gsl and pthread libraries. Install using
...
15
votes
15
votes
Accepted
Calculate the permanent as quickly as possible
gcc C++ n ≈ 36 (57 seconds on my system)
Uses Glynn formula with a Gray code for updates if all column sums are even, otherwise uses Ryser's method. Threaded and vectorized. Optimized for AVX, so don'...
15
votes
Bentley's coding challenge: k most frequent words
C++ (a la Knuth)
I was curious how Knuth's program would fare, so I translated his (originally Pascal) program into C++.
Even though Knuth's primary goal was not speed but to illustrate his WEB system ...
15
votes
Accepted
The fastest Sudoku solver
C++ - 0.201s official score
Using Tdoku (code; design; benchmarks) gives these results:
~/tdoku$ lscpu | grep Model.name
Model name: Intel(R) Core(TM) i7-4930K CPU @ 3.40GHz
~/tdoku$ # ...
14
votes
Calculate the number of primes up to n
Java, 25,725.315 seconds on this machine
This is not going to win, I just wanted to post an answer that does not use any sieves.
UPDATE: This is currently ranked at about 150,440.4386 times slower ...
14
votes
14
votes
Prime containment numbers (speed edition)
C++ (GCC) + x86 assembly, score 32 36 62 in 259 seconds (official)
Results computed so far. My computer runs out of memory after 65.
...
14
votes
High throughput Fizz Buzz
Coded in rust- modern languages can be fast too. Build with cargo build --release* and run with ./target/release/fizz_buzz. The ...
13
votes
Prime containment numbers (speed edition)
JavaScript (Node.js), score 24 in 241 seconds
Results
\$a(1)\$ to \$a(21)\$ are solved in ~15 seconds on TIO
\$a(22)=231129413434717353759619679\$ was found in ~70 seconds on my laptop
\$a(23)=...
13
votes
Accepted
Find the number of n-by-n (-1, 0, 1) matrices with zero permanent as quickly as possible
Rust, \$A(5) = 186481694371\$ in 0.2 s, \$A(6) = 19733690332538577\$ in 580 s
(Unofficial times on a Core i7-10710U with 6 cores/12 threads.)
src/main.rs
...
13
votes
Fastest yes in the west
x86-64 machine code (Linux system calls), 29B * 4.7GB/6.6GB = ~20.6 on tmpfs on Skylake
(Or even 28 bytes, but I haven't benchmarked Noah's suggestion of using the low 16 bits of the address as the ...
13
votes
The smallest area of a convex grid polygon
JavaScript (Node.js), \$n=19\$
This is a very early attempt. Given 10 minutes, it is only able to compute up to \$n=19\$ on my laptop and finds the same values as the ones listed in A070911.
It ...
12
votes
Sum of smallest prime factors
Nim, 3.6e13
Simply sieving is not the best answer when trying to calculate the highest N possible since the memory requirements become too high. Here's a different approach (started with Nim a couple ...
12
votes
12
votes
How many sorting networks?
Rust, \$n = 6\$ in ≈ 59 seconds
The main simplifying observation here is that we don’t need to run the network on all \$n!\$ permutations; it suffices to run it on all \$2^n\$ binary strings. We can ...
11
votes
Calculate the number of primes up to n
Rust, 0.37001 sec (12 June 2016)
About 10 times slower than slower than Dennis' C answer, but 10 times faster than his Python entry. This answer is made possible by ...
11
votes
Fastest yes in the west
C (clang), 88 63 bytes, 2.5GB/s
b[2048];main(){for(wmemset(b,'\ny\ny',2048);write(1,b,8192););}
Try it online! Edit: Saved 25 bytes thanks to @ceilingcat by ...
11
votes
Accepted
How quickly can you convert an NFA to a DFA?
Rust, score 15 in ≈ 6000 s
Most of my optimization effort has actually gone into memory usage rather than speed, for reasons you can see in this table of results on my system (AMD Ryzen 1800X):
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
fastest-code × 202math × 49
combinatorics × 33
code-challenge × 21
sequence × 20
number × 17
primes × 15
string × 14
number-theory × 14
grid × 9
code-golf × 8
integer × 8
game × 7
permutations × 7
optimization × 7
geometry × 6
binary × 6
graph-theory × 5
matrix × 4
sorting × 4
python × 4
puzzle-solver × 4
board-game × 4
arithmetic × 3
restricted-source × 3