<p>Is <em>CompileAssemblyFromDom</em> faster than <em>CompileAssemblyFromSource</em>?</p>

<p>It <em>should</em> be as it presumably bypasses the compiler front-end.</p>

[{'answer_id': 4659, 'author': 'Lasse V. Karlsen', 'author_id': 267, 'author_profile': 'https://Stackoverflow.com/users/267', 'pm_score': 0, 'selected': False, 'text': "<p>I've tried finding the ultimate compiler call earlier and I gave up. There's quite a number of layers of interfaces and virtual classes for my patience.</p>\n\n<p>I don't think the source reader part of the compiler ends up with a DOM tree, but intuitively I would agree with you. The work necessary to transform the DOM to IL should be much less than reading C# source code.</p>\n"}, {'answer_id': 29283, 'author': 'Jacob Krall', 'author_id': 3140, 'author_profile': 'https://Stackoverflow.com/users/3140', 'pm_score': 4, 'selected': True, 'text': "<p>CompileAssemblyFromDom compiles to a .cs file which is then run through the normal C# compiler.</p>\n<p>Example:</p>\n<pre><code>using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing Microsoft.CSharp;\nusing System.CodeDom;\nusing System.IO;\nusing System.CodeDom.Compiler;\nusing System.Reflection;\n\nnamespace CodeDomQuestion\n{\n    class Program\n    {\n\n        private static void Main(string[] args)\n        {\n            Program p = new Program();\n            p.dotest(&quot;C:\\\\fs.exe&quot;);\n        }\n\n        public void dotest(string outputname)\n        {\n            CSharpCodeProvider cscProvider = new CSharpCodeProvider();\n            CompilerParameters cp = new CompilerParameters();\n            cp.MainClass = null;\n            cp.GenerateExecutable = true;\n            cp.OutputAssembly = outputname;\n            \n            CodeNamespace ns = new CodeNamespace(&quot;StackOverflowd&quot;);\n\n            CodeTypeDeclaration type = new CodeTypeDeclaration();\n            type.IsClass = true;\n            type.Name = &quot;MainClass&quot;;\n            type.TypeAttributes = TypeAttributes.Public;\n            \n            ns.Types.Add(type);\n\n            CodeMemberMethod cmm = new CodeMemberMethod();\n            cmm.Attributes = MemberAttributes.Static;\n            cmm.Name = &quot;Main&quot;;\n            cmm.Statements.Add(new CodeSnippetExpression(&quot;System.Console.WriteLine('f'zxcvv)&quot;));\n            type.Members.Add(cmm);\n\n            CodeCompileUnit ccu = new CodeCompileUnit();\n            ccu.Namespaces.Add(ns);\n\n            CompilerResults results = cscProvider.CompileAssemblyFromDom(cp, ccu);\n\n            foreach (CompilerError err in results.Errors)\n                Console.WriteLine(err.ErrorText + &quot; - &quot; + err.FileName + &quot;:&quot; + err.Line);\n\n            Console.WriteLine();\n        }\n    }\n}\n</code></pre>\n<p>which shows errors in a (now nonexistent) temp file:</p>\n<blockquote>\n<p>) expected - c:\\Documents and Settings\\jacob\\Local Settings\\Temp\\x59n9yb-.0.cs:17</p>\n<p>; expected - c:\\Documents and Settings\\jacob\\Local Settings\\Temp\\x59n9yb-.0.cs:17</p>\n<p>Invalid expression term ')' - c:\\Documents and Settings\\jacob\\Local Settings\\Tem p\\x59n9yb-.0.cs:17</p>\n</blockquote>\n<p>So I guess the answer is &quot;no&quot;</p>\n"}]
['https://Stackoverflow.com/questions/4612', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/608/']