Languages
[Edit]
EN

CPU Benchmark - single core speed test with Fibonacci Sequence in Java

4 points
Created by:
Burhan-Boyce
458

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

  1. CPU Benchmark - Raspberry PI vs Banana PI - single core speed test with Fibonacci Sequence

  2. CPU Benchmark - single core speed test with Fibonacci Sequence in JavaScript

  3. CPU Benchmark - single core speed test with Fibonacci Sequence in AssemblyScript

  4. CPU Benchmark - single core speed test with Fibonacci Sequence in Dart

  5. CPU Benchmark - single core speed test with Fibonacci Sequence in Python

  6. CPU Benchmark - single core speed test with Fibonacci Sequence in PHP

Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join