Skip to content

Instantly share code, notes, and snippets.

@pavlenko-volodymyr
Created October 28, 2020 09:31
Show Gist options
  • Select an option

  • Save pavlenko-volodymyr/0dec473d49bfad4e74e9b1087ba1613c to your computer and use it in GitHub Desktop.

Select an option

Save pavlenko-volodymyr/0dec473d49bfad4e74e9b1087ba1613c to your computer and use it in GitHub Desktop.
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