Created
October 28, 2020 09:31
-
-
Save pavlenko-volodymyr/0dec473d49bfad4e74e9b1087ba1613c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Main { | |
| private static long test(long max) { | |
| long sum = 0; | |
| for (int i = 0; i < max; i++) { | |
| for (int j = i; j > 0; j--) { | |
| sum += j % 10 + j / 10; | |
| } | |
| } | |
| return sum; | |
| } | |
| public static void main(String[] args) { | |
| long total = 0; | |
| long tsum = 0; | |
| int testsCount = 1000; | |
| long max = (long) ((Math.random() * (10000 - 9000)) + 9000); | |
| for (int i = 0; i < testsCount; i++) { | |
| long start = System.currentTimeMillis(); | |
| tsum += test(max); | |
| total += System.currentTimeMillis() - start; | |
| } | |
| System.out.printf("Time: %dms\n", total / testsCount); | |
| System.out.printf("Sum: %d\n", tsum); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment