Advertisement
Joreto

Bench

May 14th, 2024
649
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 KB | None | 0 0
  1. package org.example.benchmark;
  2.  
  3. import org.springframework.boot.SpringApplication;
  4. import org.springframework.boot.autoconfigure.SpringBootApplication;
  5. import org.springframework.web.bind.annotation.GetMapping;
  6. import org.springframework.web.bind.annotation.RestController;
  7.  
  8.  
  9. @SpringBootApplication
  10. public class BenchmarkApplication {
  11.  
  12.     public static void main(String[] args) {
  13.         SpringApplication.run(BenchmarkApplication.class, args);
  14.     }
  15. }
  16.  
  17. @RestController
  18. class BenchmarkController {
  19.  
  20.     private static final long MAX_ITERATIONS = 1_000_000_000;
  21.  
  22.     @GetMapping("/")
  23.     public String benchmark() {
  24.         long startTime = System.currentTimeMillis();
  25.         long endTime = startTime + 60000;
  26.  
  27.         long index = 0;
  28.  
  29.         while (true) {
  30.             double x = Math.sqrt(index);
  31.             long now = System.currentTimeMillis();
  32.             if (now > endTime) {
  33.                 break;
  34.             }
  35.             index++;
  36.         }
  37.         if (index <= MAX_ITERATIONS) {
  38.             return "Your PC is need to be changed";
  39.         }
  40.  
  41.         return index + " Loops In One Minute.";
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement