|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
slow CodeDomusing its own little interpreter and works fine - all in vb 2003. I've done a new version using Codedom, expecting a blindingly fast improvement. It was reasonably painless to implement too. It's approximately 10 times slower! The compilation takes 3 times longer than the whole previous version. This I can understand(I think). My problem is that running the main method in the resulting assembly takes 4 times longer than the clunky interpreter on the same code! Why is this? I also get InvalidProgramExceptions which I gather are due to the fact that some of the statements are very long - 1000chrs+ with lots of braces. details - The code to be compiled is pretty simple - dll, one class, one method. The method contains 1000+ statements all of which look like this, but may be up to 1000 chrs. v1 is a simple variable, type single. Results(f, 411) = ((Sin(v1 / -4.0) - v1) * (v1 + Sin(v1 - -9.0))) ..... return Results Dim provider As VBCodeProvider = New VBCodeProvider Dim compiler As ICodeCompiler = provider.CreateCompiler() Try ' Build the parameters for source compilation. Dim cp As New CompilerParameters ' Add an assembly reference. cp.ReferencedAssemblies.Add("System.dll") 'cp.ReferencedAssemblies.Add("Microsoft.VisualBasic.dll") cp.GenerateInMemory = True ' Generate a class library. cp.GenerateExecutable = False cp.IncludeDebugInformation = False ' Invoke compilation. Dim cr As CompilerResults = compiler.CompileAssemblyFromSource(cp, strSource) A=cr.CompiledAssembly Dim P As Type, M As MethodInfo, obj As Object, results(,) As Single 'Get the type to use. P = A.GetType("TempClass") 'Get the method to call. M = P.GetMethod("ResultsGet") 'Create an instance obj = Activator.CreateInstance(P) Return CType(M.Invoke(obj, New Object() {fcases, indscount}), Single(,)) fcases is a 2d array of single and indscount is an integer |
|||||||||||||||||||||||