-3

I have an application perform some calculation logic and this app work with many customers

I want to change some formulas for some customers so,I found an article talking on how to execute C# code from strings here by CodeDom and it's working for my case and will solve many problems,

but I don't know about the performance of this way will be bad or not?

user897645
  • 85
  • 2
  • 8
  • 1
    How can we possibly know? Measure it with a profiler. – eddie_cat Jun 23 '14 at 16:06
  • I mean the strategy itself if i have formula x= a+b; if i store this formula in db and execute it dynamically there a time for compiling the Assembly is this time will be a problem or it's very fast? – user897645 Jun 23 '14 at 16:08

1 Answers1

2

It depends.

The first execution will be quite slow. .NET has to run the native csc.exe to compile the code. However, after the compilation step, you're left with a method like any other.

So, if you care about GUI response speed - it's not that slow. If you care about applying the same formula to a lot of data, it has very little impact as well. Caching the compiled method is the key.

Luaan
  • 62,244
  • 7
  • 97
  • 116
  • does this mean that in second time i call the same code there is no compiling time , it gets from cashed ? – user897645 Jun 23 '14 at 16:13
  • @user897645 No, you have to do the caching yourself. You need to take the result of the compilation, and e.g. create a delegate on that method. – Luaan Jun 23 '14 at 16:22
  • I can do the following 1 - Create a screen to setup formulas 2 - Compile an Assembly after saving the formula 3 - Load this assembly and call myFormula when i need in calculation logic by this way i will cash the compiler work – user897645 Jun 23 '14 at 16:40