Skip to content

measuring Java startup costs #64

@igouy

Description

@igouy

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions