I'd like to check how big is the compiled code of some classes (in bytes). I'd like to optimize them for size, but I need to know where to start.
Basically in C exponent value is calculated using the pow() function. pow() is function to get the power of a number, but we have to use #include<math. h> in c/c++ to use that pow() function.
The sqrt() function is defined in math. h header file. To find the square root of int , float or long double data types, you can explicitly convert the type to double using cast operator. int x = 0; double result; result = sqrt(double(x));
One method will be to get the size of MSIL with Reflection. You will need to loop through all methods, Property setters and getters, and constructors to determine the size of the MSIL. Also, there will be differences in size based on Debug versus Release builds.
using System.Reflection;
int totalSize = 0;
foreach(var mi in typeof(Example).GetMethods(BindingFlags.Public | BindingFlags.NonPublic |BindingFlags.Static | BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.SetProperty))
{
MethodInfo mi = typeof(Example).GetMethod("MethodBodyExample");
MethodBody mb = mi.GetMethodBody();
totalSize += mb.GetILAsByteArray().Length;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With