slow CodeDom


G

Guest

We've done an AI app which generates lots of code source, then runs the code
using 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
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

CodeDom and @ 0
EnvDTE of CodeDom 1
CodeDom Question 3
CodeDom and enums 0
CodeDOM question 0
CodeDOM question 0
Doing "&&" in codeDOM 2
Missing CodeDom Expressions? 1

Top