Click here to Skip to main content
15,884,836 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys!
I'm creating an application which has a bunch of complex algorithms that require
pretty much time to execute ...
I know that C# code (MSIL) is converted to machine code due to CLR..
but how can I manually precompile my critical and complex methods into machine code
at once...

See my artice about mutex hack:
Hack Mutex (blocking other programs)
Posted

Have a look at the NGEN tool[^].
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 25-Mar-11 13:33pm    
Makes sense, my 5.
I'm not so sure it will solve OP's problem though.
--SA

Nich, I would like your feedback after you try it. Did it imporove performance.
Thank you.
--SA
If you are sure it is the algorithms that are slowing things down (and you would be surprised how often it turns out to be something else entirely) then the best course of action is to recode them into a DLL in a native language, and call that from your C#.

Profile it first, and check that you really know what is taking time. Then focus on that bit.
 
Share this answer
 
NGEN is the tool for generating machine code. However, in some cases NGEN can cause code to be less optimized than if you used JIT. Mainly because JIT can take advantage of processor model specific instructions, whereas NGEN creates code for a family of processors. Also, NGEN complicates the deployment process because you have to deploy the NGEN images to a special location instead of just copying your exe's and dll's locally. Most of the benefits of NGEN are in startup time because the JIT penalty for each method only happens once.

The bottom line: Profile your application using JIT and NGEN and see which option is best.

Some useful links:

http://msdn.microsoft.com/en-us/magazine/cc163610.aspx[^]
http://msdn.microsoft.com/en-us/magazine/cc163808.aspx#S2[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900