Last active
October 7, 2019 09:01
-
-
Save mvoitko/441779a0fa01553b5c9cb9f90ebc51ea to your computer and use it in GitHub Desktop.
This file contains 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 static void main(String[] args) { | |
long startTime = System.currentTimeMillis(); | |
int n = 100 * 1000; | |
long res = compute(n); | |
long endTime = System.currentTimeMillis(); | |
System.out.println(res); | |
// 2.2 GHz ~ 2.2 * 10^9 op/sec | |
// alg ~ n^2 op ~ 10^10 op | |
// total time: 10^10 / (22 * 10^8) ~ 4 sec | |
// let's double the input: | |
// n = 200000 | |
// totatl time = prev_time * 4 ~ 16 sec | |
System.out.println((endTime - startTime) / 1000); | |
} | |
| |
static long compute(int n) { | |
long sum = 0; | |
for (int i = 0; i < n; ++i) { | |
for(int j = 0; j < n; ++j) { | |
sum += i*j; | |
} | |
} | |
return sum; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment