CPU Benchmark - single core speed test with Fibonacci Sequence in Java
In this short article, I would like to show Fibonacci Sequence test that is run on a single core. The test source code was converted from C++ to Java - check source article.
Example Test.java
file:
public class Test {
public static void main(String[] args) {
long tmp, a = 0, b = 1;
System.out.println("Started!");
long t1 = System.currentTimeMillis();
for (long i = 0; i < 10000L; ++i) {
for (long j = 0; j < 1000000L; ++j) {
tmp = b;
b = a + b;
a = tmp;
}
}
long t2 = System.currentTimeMillis();
long dt = t2 - t1;
System.out.println("Finished!");
System.out.println("Result: " + b);
System.out.println("Time: " + (0.001 * dt) + "s");
}
}
Test compilation:
javac Test.java
Test running:
java Test
Example output:
Started!
Finished!
Result: -1667179358074339043
Time: 15.425s
Note:
Result: -1667179358074339043
printing is used only to prevent against automiatic optimization.
Used Java:
openjdk version "1.8.0_292"
OpenJDK Runtime Environment Corretto-8.292.10.1 (build 1.8.0_292-b10)
OpenJDK 64-Bit Server VM Corretto-8.292.10.1 (build 25.292-b10, mixed mode)
Used OS: Windows 10 x64
Used PC:
- Ryzen 9 5900x
- DRR 4 (2x 32GB)
- Samsung SSD M.2 970 EVO (1TB)
- GeForce GTX 970 (4GB RAM)
See also
-
CPU Benchmark - Raspberry PI vs Banana PI - single core speed test with Fibonacci Sequence
-
CPU Benchmark - single core speed test with Fibonacci Sequence in JavaScript
-
CPU Benchmark - single core speed test with Fibonacci Sequence in AssemblyScript
-
CPU Benchmark - single core speed test with Fibonacci Sequence in Dart
-
CPU Benchmark - single core speed test with Fibonacci Sequence in Python
-
CPU Benchmark - single core speed test with Fibonacci Sequence in PHP