Benchmarks

Benchmark: 3n + 1 Problem

The Collatz Conjecture, also known as 3n + 1, is a mathematical problem that has puzzled mathematicians for years. The conjecture states that if you take any positive integer n, and if n is even, divide it by 2, and if n is odd, multiply it by 3 and add 1, and repeat this process, you will eventually reach the number 1. This benchmark tests the performance of the 3n + 1 problem on the number “837,799” which takes 524 steps to reach 1.

number math algorithm

All-Time Rankings

Rank Language Average Time Best Time Worst Time
1 C (GCC) 3.193µs 2.956µs 3.466µs
2 Go 3.227µs 2.966µs 3.466µs
3 C++ (G++) 3.388µs 3.146µs 3.737µs
4 C++ (Clang++) 3.537µs 3.366µs 3.937µs
5 C (Clang) 3.582µs 3.326µs 3.867µs
6 Rust 4.107µs 3.577µs 5.260µs
7 Kotlin (Native) 11.937µs 11.210µs 12.954µs
8 Ruby 49.643µs 45.536µs 58.269µs
9 Java 1,498.223µs 43.752µs 36,261.248µs
10 JavaScript (Node) 5,040.938µs 155.962µs 66,412.173µs
11 Python 5,759.675µs 120.617µs 42,118.524µs
12 JavaScript (Deno) 8,051.456µs 188.945µs 51,916.441µs
13 PHP 9,708.805µs 399.360µs 63,574.100µs
14 Kotlin (JVM) 14,296.805µs 520.658µs 74,936.054µs
15 JavaScript (Bun) 22,407.513µs 645.441µs 64,841.530µs

Average Times

Median Times

Best-Case Scenario Times

Worst-Case Scenario Times