Skip to content

Advice on very fast execution

Ned Goodhue

Asked May 1, 2007, 6:41 AM EDT3 answers
Share
LinkedInX
Hi everybody,

I'm building a Monte Carlo simulation - not a gambling site, but a type of model that runs millions of times using a random number generator to pick a value for independent variables from a probability distribution that are then used in other calculations.

The inner loops of the model run millions of times and have to be blazingly fast or the model will take weeks, even months to run. We're writing the application in C# and I'm afraid that the overhead of the interpreter from intermediate code into machine code will be a killer.

Any suggestions as to a language I can use for the inner loops that compiles into fast machine code whose object code I can link back into the C# code?

Many thanks, Ned

3 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Mike Gold
    0
    It might help to describe what you are trying to do.

    Are you trying to get a pure random number after millions of random generations or are you getting a million random numbers?

    If you just want a loop that generates random numbers, why not spin it in a thread with some sort of sleep delay and have it run in parallel?

    If you are looking for a more "random" random number, you can use the DateTime.Now.Ticks as a seed.
    0
  • 0
    My problem is not generating the random number, it's the code that does all the work at the heart of the model. It's a fair bit of math plus a few SQL calls.

    The problem is that this code has to run millions of times. If that code is going to be interpreted from intermediate code to machine code each time it runs, it will be too slow. I need this inner loop to be compiled down to machine code by a machine-specific compiler then linked into the C# shell.

    I'm trying to figure out how best to do that.
    0
  • Mike Gold
    0
    If you are doing SQL calls each time(millions of time), this will be your bottle neck anyway.  If it's only a few sql calls then keep in mind that C# is not interpreted but uses an efficient JIT Compiler (Just in Time Compile), so you are not really using interpreted code.  The efficiency then will depend on how well you use integers, floating point, etc.

    The only slow down may be garbage collection of large data.
    0