开发者

f# slow compilation

开发者 https://www.devze.com 2023-03-29 06:51 出处:网络
Is there anything I can do to make f# code compile faster apart from (or better yet instead of) running ngen?

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 = pr开发者_开发知识库ovider.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


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()
0

精彩评论

暂无评论...
验证码 换一张
取 消