Why did any Java / Clojure program slow down when launched from Leiningen?

When testing the Clojure application and trying to identify performance problems, I noticed this peculiar behavior: even when the entire program is written in Java, it seems that there is a significant slowdown when starting from Leiningen.

Say I have this Java program:

public class Foo {
    public static void main(String[] args) throws Exception {
        for (int i = 0; i < 10; i++)
             run();
    }

    public static void run() {
        final long start = System.nanoTime();

        Random r = new Random();
        double x = 0;
        for(int i=0; i<50000000; i++)
            x += r.nextDouble();

        final long time = TimeUnit.MILLISECONDS.convert(System.nanoTime() - start, TimeUnit.NANOSECONDS);
        System.out.println("time (ms): " + time + " total: " + x);
    }
}

When I just run the program, I get a runtime (per run) of about 1 s. However, when I run it from leiningen as follows:

lein run -m Foo

I get a runtime of about 2 seconds! How does Clojure / Leiningen significantly slow down a complete Java program? What am I doing wrong?

(, JIT). Java 7 .

EDIT: , . Clojure. , Clojure, . , .

: lein trampoline ! ( , ) , , Leiningen, Clojure.

: Clojure. 5x.

+5
3

, JIT.

JIT, , , :

  • , JIT
  • (, Random),
+1

leiningen takes about a second to start.

-1
source

All Articles