gefei
gefei

Reputation: 19776

Scala: strange performance of scala programs in IntelliJ IDEA

I wanted to do some benchmarking of Scala using ProjectEuler https://projecteuler.net/ problems. Here is my solution for problem 2.

object Euler002 {
    def fib(a: Int, b: Int, c: Int, sum: Int, end: Int): Int = {
        if (c > end) sum
        else fib(b+c, c+b+c, c+b+b+c+c, sum+c, end)
    }

    def euler002() = {
        fib(1, 1, 2, 0, 4000000)
    }

    def main(args: Array[String]) {
        val a = System.currentTimeMillis()
        println (euler002())
        println ("time elapsed: " + (System.currentTimeMillis()-a) + " millisec")
    }
}

What this program does is actually irrelevant. What I find strange ist that when I run this program in the console, by typing scala Euler002.scala, then I got the feedback time elapsed: 1 millisec (sometime it's 0 millisec, sometimes it's 2, but that does not matter), but when I run it in IntelliJ IDEA 14, then it says time elapsed: 140 millisec.

Why does it run so much slower in IntelliJ than in the console?

Upvotes: 0

Views: 36

Answers (1)

user4645134
user4645134

Reputation:

Looking at the source code for the Scala plugin's class runner, it seems like there is some overhead which adds those extra milliseconds.

Upvotes: 3

Related Questions