Question: Speeding up simulations

Dear Maple users

I am trying to simulate the distribution of Q-values (Karl Peason) in a Contingency table. In that regard I need to use a two dimensional iteration. It require quite a lot of time to perform the computations. Using the values below, it required 1.3 mio iterations and took about 5 minuttes on my computer. My question is if there are ways I can speed it up? It might be using different commands, which are executed faster, performing computations in the kernel, etc. I don't have any overview myself over this issue and hope there are users who can help. My code is listed below. I have two procedures. The first generates a random contingency table and calculate the Q-value. The latter procedure is calling the first procedure many times (here 1000), and collecting all the Q-values. In the end a Histogram is generated from the data.   


Please Wait...