简体   繁体   中英

Is F# compiler trick?

I create a program to calculate the integration of an variable-include-expression such as "x" , "x+1" , "sin(x)"

When i debug in vs , i got the very slow calculation-process

but when i open the output execute (in bin/debug/) i got the pretty speed process, the result appear almost immediately , and of course equal to the result i got by the above test

please tell me what is that trick , why it happened ?

and if can , please guide me the algorithm to calculate the integration of arbitrary var-expression

thank alot , i love stack exchange so much ^^

it's normal to have a program running slower in debug mode than in normal free execution. There are no tricks.

If you run without debugging from visual studio you will also get good performance. The reason debugging is slowing your program down is two-fold.

First there are several optimizations that the JITer can do but will not when a debugger is attached, these optimizations make stepping through code impossible, but output equivalent information.

For instance the following code could potentially be completely removed by the JIT (except the definition).

int[] data = new int[10000];
for (int i = 0; i < data.Length; i++)
    data[i] = 0;

The reason is the constructor for the array clears the contents and therefore this operation is redundant. However when debugging you may want to step through the code so it is preserved.

Additionally during high performance sections you will often have a 50% speed-down due to every other operation being a NOP, which does nothing but still takes a clock cycle. These NOPs are what enable breakpoints to function, but would not be emitted by the JIT if a debugger were not attached.

Note that what I am saying is a generalization, the actual interactions of the compiler and JIT are a bit more complex.

For your second question, the multivariate numerical integration, you can have a look at Monte Carlo integration .

If the function to be integrate is a probability distribution, you may want to read Gibbs sampling method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM