Skip to content

Instantly share code, notes, and snippets.

@mvoitko
Last active October 7, 2019 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mvoitko/441779a0fa01553b5c9cb9f90ebc51ea to your computer and use it in GitHub Desktop.
Save mvoitko/441779a0fa01553b5c9cb9f90ebc51ea to your computer and use it in GitHub Desktop.
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