Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

measuring Java startup costs #64

Open
igouy opened this issue Jul 29, 2018 · 5 comments
Open

measuring Java startup costs #64

igouy opened this issue Jul 29, 2018 · 5 comments

Comments

@igouy
Copy link

igouy commented Jul 29, 2018

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);     
      }
   }
}
@frol
Copy link
Owner

frol commented Jul 29, 2018

I encourage you to play with the solutions on your own computer and you can even fork or create your own benchmark from scratch!

While I agree that it is unfair to compare runtime performance including the startup time, it is still a valid benchmark if you consider it to be a CLI application. I consider increasing the number of operations by 10, but even then it will include the startup time. I will consider measuring the time inside the solutions for the next benchmark iteration to avoid the startup times, but there is no ETA on that.

@igouy
Copy link
Author

igouy commented Jul 29, 2018

…or create your own benchmark from scratch!

Been there; done that.

…even then it will include the startup time.

Which might be very significant or very insignificant — and as-long-as the difference is shown, you can allow others to decide if the difference seems significant to them.

@igouy
Copy link
Author

igouy commented Aug 1, 2018

fwiw the same experiment with C# seems to show a smaller difference (dotnet --version 2.1.302)

        static void Program_Main() {
            var tree = new Tree();
            var cur = 5;
            var res = 0;

            for (var i = 1; i < 1000000; i++) {
                var 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) {
                    if (tree.hasValue(cur))
                        res++;
                }
            }
            Console.WriteLine(res);
        }

        static void Main() {
            for (var i = 1; i < 100; i++) {
                Program_Main
            }
        }
    }
1
real	0m1.264s
user	0m1.231s
sys	0m0.032s

100
real	1m55.594s
user	1m55.365s
sys	0m0.200s

@Aivean
Copy link

Aivean commented Nov 17, 2021

My two necroposting cents.

It's completely unfair to benchmark languages with JIT, such as all JVM, Python (PyPY), Javascript vs native binaries without proper warmup. While I agree that start time metric is important in certain scenarios, this project claims to measure performance, not start up time! Paragraphs like this:

This turned out to be a good benchmark of memory-intensive operations, which should have been pushed memory management implementations to their edge.

are completely misleading when you include start up and JIT compilation time into measurement.

The argument:

it is still a valid benchmark if you consider it to be a CLI application

doesn't really hold, as there are ways to eliminate startup cost for JIT languages.

@frol
Copy link
Owner

frol commented Nov 17, 2021

It is a completely unscientific benchmark. My initial goal was to compare naïve implementations of exactly the same problem in different languages. This benchmark is good enough for me, and I never advocated for using this benchmark for anything serious. Keep in mind that there cannot be an ultimate benchmark. I also believe there is no ultimate programming language either

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants