The probability value presented is single-sided. The literature considers that the Kolmogorov Smirnov test has very little power with a high chance of a type II error, i.e. of not finding a difference when there is one. Unless there are serious theoretical or other reasons for using the K-S, use of the gamma is preferable. The algorithm works with four loops, one for each degree of freedom. Three loops are 'dumb' and one, the last, loop is 'smart'.
Speed can be a problem.
For each additional row speed will decrease with an additional factor determined by the size of the additional margin.