Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

f# slow compilation

Is there anything I can do to make f# code compile faster apart from (or better yet instead of) running ngen?

And what is approximate benchmark "hello world" compilation time (or better said compiler startup time+compilation time) for say pentium 4 machine?

Edit There are nuances as it turns out:)

So first, can anyone explain what is start-up time of compiler? And why is it slow. Also links to information on the whole f# compilation process would be appreciated.

Context: f# compiler is repeatedly invoked on small snippets of code through

using (CodeDomProvider provider = new Microsoft.FSharp.Compiler.CodeDom.FSharpCodeProvider())
{
  //start time
  cr = provider.CompileAssemblyFromSource(cp, new string[] { data.Program });
  //end time
}

The time difference is ~6 sec. So the question basically is what can be done, apart from ngen? You can see for yourself here:rundotnet

like image 562
ren Avatar asked Aug 20 '11 18:08

ren


1 Answers

This takes 0.9s on my computer (AMD Athlon 64 X2 4600):

#r "FSharp.Compiler.CodeDom"

open System.Reflection
open System.CodeDom.Compiler
open Microsoft.FSharp.Compiler.CodeDom

let comp() =
    use provider = new FSharpCodeProvider() 
    let code = "module pp\n printfn \"Hello world\""
    let cp = new CompilerParameters() 
    cp.GenerateInMemory <- true 
    provider.CompileAssemblyFromSource(cp, [|code|]) |> ignore
#time
comp()
like image 78
Mauricio Scheffer Avatar answered Sep 21 '22 15:09

Mauricio Scheffer