-
Couldn't load subscription status.
- Fork 68
Open
Description
The programs don't do much work so about 15% of the Java time is just startup costs that disappear (become amortised) if the program is run longer.
So performing 10 times the work and dividing the time by 10 gives a magical performance boost:
class Main {
public static void program_main(String[] args) {
Tree tree = new Tree();
int cur = 5;
int res = 0;
for (int i = 1; i < 1000000; i++) {
int a = i % 3;
cur = (cur * 57 + 43) % 10007;
if (a == 0) {
tree.insert(cur);
} else if (a == 1) {
tree.erase(cur);
} else if (a == 2) {
boolean hasVal = tree.hasValue(cur);
if (hasVal)
res++;
}
}
System.out.println(res);
}
public static void main(String[] args){
for (int i=0; i<10; ++i){
Main.program_main(args);
}
}
}
Metadata
Metadata
Assignees
Labels
No labels