4
votes

I recently noticed that F# Interactive is much faster than the compiled version (in either Release or Debug mode). Here is an example:

let rec fib n = if n < 3 then 1 else fib (n-1) + fib (n-2)

[<EntryPoint>]
let rec main argv = 
    let w = System.Diagnostics.Stopwatch()
    w.Start()
    fib 45
    w.Stop()
    printfn "%d" w.ElapsedMilliseconds
    System.Console.ReadLine()
    0

When compiled in release mode then run this outputs "12784", when run in F# Interactive it outputs "4986". I am running it in Interactive mode using "main [||];;".

Something weird is definitely going on, but I have no idea what!

EDIT [Specs]: F# 3.0 for .NET 4. The optimize code and generate tail call flags are set and I am compiling for x86. I am running this on an i7 950. I am using visual studio 2012.

2
What are your F#/.NET framework/Visual Studio versions? Is the compiled version x86 or x64? Did you run the compiled program outside VS? - pad
Sorry, I really should have put my specs in, very stupid of me. F# 3.0 for .NET 4. The optimize code and generate tail call flags are set and I am compiling for x86. I am running this on an i7 950. I am using visual studio 2012. - Maltic
I can confirm they are almost exactly the same under .NET 4.5. Mystery solved! Thanks very much! - Maltic
@Maltic - please post this as an answer for anyone who has the same issue in the future - John Palmer

2 Answers

3
votes

Ran executable outside of VS2012 as suggested by pad, then changed to .NET 4.5. This equalized the run times.

-1
votes

Please see my answer : What makes this F# so slow in VS2012?

you have to add Fsharp.core.dll file to your exe file to make it load faster.