# How to speed up my function?

I implemented a formula with Mathematica as follows:

calcFitKnots[{m_, n_}, p_, paras_] /; m < n :=
Module[{deltaT, mu, Ubar},
deltaT = Differences@paras;
mu = ConstantArray[0.0, m*n + 1];
Do[
mu[[j + 1]] = mu[[j]] + deltaT[[Floor[(j - 1)/n] + 1]]/n,
{j, 1, m*n}
];
Ubar = mu[[1 ;; m*n + 1 ;; m]];
Join[
ConstantArray[0.0, p + 1],
MovingAverage[ArrayPad[Ubar, -1], p], ConstantArray[1.0, p + 1]]
]


When I applied it into my task, I found it is not fast(I need to call calcFitKnots at least 100 times when I executed the main program once).

rowLens = {108, 110, 108, 107, 105, 107, 107, 110, 115, 124, 132, 136, 141, 147, 153, 161, 162, 171, 191, 210};
rowParas = {{0,0.0101741,0.0237451,0.0345857,0.049517,0.0603641,0.0771377,0.0875217,0.105587,0.116573,0.133776,0.151797,0.155668,0.161913,0.173007,0.177492,0.190084,0.195102,0.206872,0.211803,0.223631,0.22743,0.237618,0.240743,0.241731,0.246368,0.253254,0.255565,0.262697,0.268237,0.274147,0.281468,0.292862,0.296743,0.302383,0.314214,0.325206,0.334831,0.345406,0.356734,0.371585,0.374564,0.3777,0.392418,0.40299,0.415695,0.428681,0.438849,0.450907,0.460502,0.466859,0.482677,0.494294,0.50626,0.519547,0.529545,0.545441,0.548966,0.552311,0.565882,0.575487,0.582766,0.592549,0.597337,0.60683,0.610092,0.612783,0.625697,0.639783,0.642749,0.64784,0.660606,0.6673,0.683813,0.685888,0.688051,0.706541,0.723674,0.730051,0.741252,0.751671,0.757098,0.774282,0.781878,0.796845,0.803227,0.817033,0.821739,0.834871,0.838326,0.851033,0.854311,0.866639,0.871599,0.882254,0.891812,0.897198,0.903792,0.912242,0.919951,0.929074,0.939037,0.947168,0.956377,0.967488,0.97567,0.991213,1.},{0,0.0131039,0.0231193,0.0371254,0.0482088,0.0625422,0.075124,0.0893899,0.10309,0.118677,0.130189,0.142003,0.152708,0.165633,0.171577,0.183433,0.188578,0.199926,0.20535,0.21638,0.22342,0.231518,0.239902,0.244079,0.250635,0.251716,0.252484,0.255974,0.257515,0.25993,0.265394,0.274238,0.276974,0.279432,0.291329,0.303823,0.309935,0.318726,0.329812,0.340685,0.351629,0.363699,0.372981,0.381981,0.395113,0.409495,0.418166,0.427045,0.440274,0.44965,0.463337,0.478277,0.486394,0.503675,0.507804,0.517324,0.528038,0.532524,0.549304,0.563352,0.567075,0.5697,0.581517,0.586944,0.59578,0.602462,0.609949,0.621424,0.623695,0.626491,0.640224,0.653673,0.658568,0.667071,0.674376,0.67975,0.69173,0.705088,0.712311,0.718351,0.734265,0.747947,0.75868,0.774099,0.782722,0.797049,0.805461,0.816909,0.825604,0.834256,0.84308,0.849908,0.858703,0.865329,0.873791,0.882415,0.888478,0.897556,0.902117,0.905694,0.917629,0.931243,0.933799,0.93656,0.951666,0.968817,0.972712,0.976343,0.995634,1.},{0,0.0158305,0.022381,0.0393338,0.046667,0.0642511,0.0727443,0.0906404,0.10008,0.119976,0.125973,0.131774,0.147532,0.156764,0.166305,0.174564,0.183009,0.190846,0.200129,0.207956,0.219666,0.221061,0.222467,0.234501,0.244058,0.246724,0.256066,0.259496,0.269356,0.28294,0.284554,0.286356,0.30172,0.314323,0.323715,0.337353,0.345271,0.352753,0.368944,0.388132,0.392673,0.39713,0.415949,0.430844,0.441013,0.45721,0.461789,0.464925,0.481608,0.490086,0.503509,0.513907,0.525603,0.538353,0.547117,0.555597,0.565336,0.575245,0.580518,0.58996,0.593306,0.600901,0.604698,0.607133,0.618889,0.629995,0.635122,0.640825,0.653974,0.669721,0.672448,0.675601,0.691763,0.705145,0.713982,0.727786,0.734824,0.73943,0.75675,0.765803,0.780932,0.78969,0.804626,0.810696,0.824403,0.827207,0.82904,0.841424,0.846074,0.856096,0.861093,0.870887,0.875087,0.883565,0.887853,0.890415,0.901686,0.910899,0.917081,0.924727,0.93266,0.939974,0.950366,0.962908,0.970204,0.975826,0.992462,1.},{0,0.0163309,0.0220315,0.0396445,0.0455216,0.064714,0.0703397,0.0909479,0.0964765,0.11793,0.123464,0.133858,0.143564,0.147755,0.160736,0.16558,0.177182,0.181689,0.194667,0.197659,0.201429,0.213844,0.225929,0.227611,0.229921,0.241186,0.246115,0.258615,0.260322,0.261894,0.275632,0.290956,0.29529,0.302242,0.315374,0.324837,0.339721,0.360202,0.363276,0.366665,0.388446,0.410771,0.414055,0.416949,0.436549,0.447933,0.460061,0.47335,0.481477,0.496406,0.502342,0.518917,0.52185,0.527344,0.541721,0.545609,0.552667,0.562183,0.566178,0.576375,0.581067,0.589415,0.594203,0.601731,0.608215,0.614798,0.624241,0.631198,0.638872,0.65034,0.66107,0.671602,0.68485,0.691753,0.697197,0.712808,0.726497,0.735968,0.752852,0.75919,0.776954,0.782771,0.798825,0.806404,0.818431,0.828019,0.835688,0.845663,0.850708,0.860373,0.864414,0.874025,0.878569,0.887854,0.895147,0.9024,0.913313,0.916272,0.918913,0.931851,0.945089,0.948923,0.953424,0.967281,0.976922,0.989448,1.},{0,0.0132088,0.0217789,0.0358865,0.0449524,0.0601878,0.0693579,0.0855249,0.0947144,0.111127,0.120717,0.134867,0.141054,0.152808,0.158027,0.168603,0.173993,0.185249,0.190761,0.199699,0.205863,0.210685,0.22145,0.230437,0.238701,0.247943,0.260025,0.266017,0.272648,0.286736,0.299994,0.309549,0.327099,0.33152,0.335448,0.356119,0.374645,0.383266,0.392858,0.410112,0.430684,0.434734,0.440521,0.455212,0.461685,0.475561,0.483933,0.49536,0.505068,0.515215,0.525858,0.535383,0.545947,0.554595,0.562266,0.569921,0.576299,0.583217,0.590155,0.596282,0.607211,0.609435,0.612077,0.627662,0.645471,0.648104,0.650735,0.669485,0.684225,0.691847,0.702024,0.71183,0.718364,0.732797,0.744292,0.755188,0.768059,0.778245,0.790235,0.802552,0.810491,0.822711,0.827123,0.829783,0.841523,0.847568,0.855758,0.861982,0.868908,0.875256,0.882825,0.888795,0.899473,0.901452,0.903894,0.915051,0.923658,0.931086,0.940503,0.9471,0.952503,0.96545,0.977927,0.986543,1.},{0,0.0102132,0.0215395,0.0322841,0.044412,0.0558513,0.0684252,0.0803312,0.0930367,0.104612,0.116942,0.126596,0.136109,0.144032,0.15247,0.159442,0.167899,0.175208,0.184453,0.194576,0.200967,0.214542,0.2183,0.233481,0.237338,0.253061,0.259656,0.275564,0.279207,0.282006,0.29954,0.3098,0.324826,0.344343,0.350465,0.359298,0.377262,0.392043,0.404936,0.415774,0.43032,0.446102,0.453624,0.469309,0.472604,0.479516,0.489221,0.493016,0.506952,0.512467,0.525591,0.531392,0.543313,0.54834,0.558995,0.563386,0.573073,0.578733,0.587839,0.599333,0.603695,0.609373,0.623055,0.635683,0.646587,0.66139,0.668649,0.673546,0.690271,0.70473,0.711455,0.721796,0.730241,0.735426,0.750104,0.758837,0.772205,0.780826,0.796588,0.799601,0.802719,0.816338,0.82513,0.833856,0.845609,0.849117,0.857408,0.860883,0.862706,0.872406,0.875208,0.88276,0.886688,0.88866,0.899253,0.905789,0.914552,0.92742,0.928981,0.930646,0.944388,0.954934,0.963421,0.978111,0.982172,0.992795,1.},{0,0.00738261,0.021449,0.0290101,0.0441794,0.0520211,0.0679685,0.0758303,0.0920197,0.0989906,0.114051,0.119421,0.132213,0.136488,0.148095,0.151633,0.163115,0.166663,0.178763,0.184427,0.195376,0.20427,0.213148,0.22346,0.232351,0.24268,0.253453,0.264883,0.274514,0.288823,0.296282,0.311607,0.318415,0.323821,0.345323,0.364862,0.377322,0.394721,0.4036,0.412608,0.427323,0.436508,0.449605,0.461321,0.469538,0.481406,0.487352,0.499579,0.504522,0.517579,0.521793,0.534909,0.538627,0.551107,0.55312,0.556383,0.566531,0.570722,0.582478,0.593292,0.600795,0.611238,0.62116,0.62889,0.644985,0.658941,0.671781,0.687802,0.692692,0.696466,0.711989,0.724496,0.732042,0.745775,0.749637,0.752486,0.768482,0.773283,0.783529,0.791375,0.795196,0.809417,0.822125,0.826708,0.83075,0.841622,0.849322,0.856766,0.864158,0.86939,0.876763,0.881671,0.889274,0.895572,0.902849,0.91316,0.916444,0.920855,0.930568,0.937915,0.947494,0.961491,0.963753,0.966913,0.980404,0.98656,1.},{0,0.00463631,0.021411,0.0242275,0.030784,0.0443665,0.0485858,0.0668573,0.072179,0.0894096,0.0952738,0.109486,0.115442,0.126672,0.132391,0.141769,0.147526,0.156381,0.162275,0.172694,0.177339,0.188236,0.192162,0.19487,0.20877,0.214354,0.228186,0.233274,0.247907,0.253261,0.26788,0.275292,0.289514,0.301617,0.313917,0.333961,0.342138,0.349418,0.37501,0.38423,0.404256,0.423359,0.4275,0.432561,0.446769,0.454084,0.465574,0.474528,0.482538,0.491929,0.49849,0.508795,0.514585,0.525978,0.530754,0.542768,0.546164,0.555024,0.560408,0.563155,0.576937,0.586968,0.597124,0.61167,0.617756,0.622352,0.640564,0.649442,0.667711,0.673482,0.679612,0.694893,0.710217,0.712563,0.714754,0.729421,0.739414,0.748195,0.761057,0.7673,0.781075,0.788001,0.800326,0.813681,0.817298,0.820346,0.832813,0.84597,0.848914,0.851223,0.862196,0.866337,0.874405,0.878748,0.886571,0.891152,0.900741,0.903412,0.907703,0.916279,0.921842,0.931751,0.943653,0.947349,0.952494,0.962749,0.968928,0.980582,0.989772,1.},{0,0.00626506,0.0207312,0.0279797,0.0427025,0.0508062,0.0653762,0.0742309,0.0873201,0.0967464,0.106731,0.11612,0.123367,0.132434,0.138073,0.146998,0.15229,0.161279,0.168028,0.176397,0.186202,0.193025,0.205105,0.211256,0.223722,0.23042,0.242696,0.249572,0.262658,0.269154,0.284852,0.288359,0.294247,0.309427,0.322765,0.336102,0.343289,0.354157,0.371123,0.385842,0.401451,0.409568,0.418174,0.430835,0.446046,0.448747,0.450842,0.464078,0.470426,0.479853,0.487065,0.494489,0.502319,0.510138,0.51963,0.525523,0.536304,0.540824,0.553107,0.555025,0.558408,0.571609,0.574773,0.579881,0.595,0.611375,0.614677,0.617624,0.635512,0.640364,0.649359,0.659175,0.66409,0.678451,0.69287,0.696337,0.69962,0.713256,0.726138,0.729204,0.733155,0.744489,0.75106,0.762202,0.770931,0.781417,0.79027,0.803556,0.806961,0.810295,0.822554,0.834817,0.838035,0.841642,0.851483,0.856581,0.865707,0.869792,0.877908,0.881345,0.889851,0.893602,0.902696,0.908567,0.917203,0.927449,0.932061,0.938863,0.946661,0.951785,0.962924,0.972639,0.980934,0.992899,1.},{0,0.00897774,0.0206608,0.0308362,0.0423657,0.0536982,0.0646482,0.0770065,0.0860389,0.0989995,0.104836,0.117631,0.119633,0.122671,0.132695,0.136283,0.146547,0.150185,0.159809,0.162599,0.164422,0.176097,0.182149,0.192631,0.200937,0.2109,0.219382,0.229789,0.237755,0.248343,0.256623,0.267232,0.277148,0.287586,0.301807,0.307956,0.315224,0.330453,0.345057,0.360964,0.366025,0.371138,0.388525,0.397034,0.412326,0.416992,0.420497,0.435696,0.448426,0.451497,0.462497,0.466843,0.476778,0.482175,0.490192,0.495857,0.504435,0.508645,0.513238,0.522022,0.529861,0.535943,0.545279,0.550015,0.560679,0.564524,0.576437,0.581986,0.594449,0.609043,0.612213,0.619351,0.629909,0.631953,0.635332,0.647539,0.654651,0.665031,0.678982,0.680858,0.682613,0.696372,0.709402,0.711627,0.713927,0.726237,0.735723,0.742273,0.755172,0.757613,0.763095,0.773638,0.7764,0.784585,0.792771,0.79619,0.809599,0.823117,0.825085,0.826737,0.838339,0.844802,0.852498,0.860087,0.865372,0.872022,0.87693,0.883347,0.888684,0.895962,0.901655,0.911604,0.915326,0.921626,0.929098,0.933726,0.944647,0.954257,0.961667,0.974232,0.979232,0.993959,0.996238,1.},{0,0.0117089,0.0206779,0.0338021,0.0422101,0.056796,0.0641991,0.0800873,0.0835915,0.0893363,0.100294,0.105382,0.116307,0.123329,0.130949,0.138245,0.144653,0.151727,0.159258,0.165411,0.176104,0.179453,0.187464,0.194216,0.197755,0.211544,0.216109,0.230243,0.233542,0.244884,0.249609,0.250305,0.253717,0.266813,0.270798,0.28593,0.292796,0.307205,0.323728,0.326103,0.328551,0.345845,0.348162,0.350386,0.36737,0.383607,0.386265,0.392319,0.405826,0.408495,0.412743,0.426502,0.434849,0.445173,0.457518,0.462427,0.473379,0.477624,0.486635,0.490857,0.499012,0.501901,0.506163,0.511644,0.516918,0.522098,0.525585,0.5338,0.539441,0.546276,0.552955,0.558676,0.566179,0.571579,0.579921,0.587779,0.595017,0.604243,0.611521,0.624799,0.627891,0.639571,0.646279,0.654153,0.663476,0.668104,0.672337,0.682298,0.692624,0.69691,0.701175,0.711278,0.720849,0.725002,0.729724,0.737838,0.743277,0.752968,0.761043,0.770143,0.77921,0.788499,0.797201,0.809922,0.812552,0.814958,0.826425,0.834765,0.841296,0.851418,0.853735,0.858039,0.863971,0.866309,0.874551,0.877218,0.885895,0.888569,0.898397,0.901962,0.912604,0.918677,0.928228,0.9379,0.944752,0.957825,0.959732,0.962256,0.974839,0.980258,0.993236,1.},{0,0.0144151,0.0206725,0.0367179,0.0410606,0.0522227,0.0604033,0.0640337,0.0800191,0.0874184,0.0988369,0.108656,0.115115,0.125936,0.12933,0.13983,0.141373,0.141434,0.142787,0.152944,0.156793,0.166077,0.173265,0.180574,0.191414,0.197336,0.209603,0.215918,0.227579,0.234473,0.245192,0.252238,0.263043,0.270266,0.28234,0.288638,0.300915,0.305373,0.30916,0.323151,0.332291,0.343303,0.352353,0.365851,0.368761,0.372274,0.385819,0.398644,0.403968,0.418041,0.423383,0.436056,0.446188,0.453916,0.466546,0.470413,0.481563,0.484258,0.492842,0.494994,0.496128,0.504148,0.507993,0.513651,0.519319,0.5236,0.530919,0.532758,0.534125,0.542578,0.545847,0.553281,0.557157,0.563781,0.568231,0.575144,0.580272,0.590619,0.593249,0.596459,0.60774,0.617959,0.623426,0.632631,0.636513,0.643597,0.651553,0.655827,0.660348,0.66813,0.675257,0.681646,0.688416,0.69539,0.702438,0.709058,0.715265,0.72236,0.729107,0.734473,0.744433,0.748697,0.761344,0.765088,0.778881,0.782327,0.795872,0.801426,0.812214,0.822409,0.826853,0.833512,0.839291,0.842206,0.851058,0.855935,0.862014,0.867228,0.872243,0.877801,0.883073,0.889527,0.895542,0.903737,0.910068,0.920791,0.925369,0.934545,0.939814,0.942778,0.954876,0.96152,0.971787,0.98031,0.990224,1.},{0,0.0162303,0.0212312,0.0372273,0.0439194,0.0588326,0.0674399,0.0797348,0.091119,0.0975752,0.107244,0.111949,0.115298,0.125462,0.131901,0.138864,0.145051,0.152329,0.157051,0.164939,0.168226,0.170625,0.181043,0.18885,0.197983,0.207197,0.216963,0.225144,0.235369,0.242378,0.252736,0.259449,0.270255,0.277545,0.288247,0.297943,0.305617,0.314483,0.322877,0.336245,0.34101,0.354237,0.361419,0.371874,0.383757,0.386937,0.390627,0.401995,0.412358,0.418029,0.428809,0.43589,0.445116,0.456841,0.46071,0.466764,0.474633,0.478419,0.487757,0.492019,0.498996,0.503347,0.508242,0.514853,0.515925,0.517113,0.524229,0.528502,0.533723,0.538988,0.542825,0.548922,0.55139,0.556967,0.55879,0.559858,0.566549,0.568698,0.576251,0.577786,0.58125,0.590277,0.597859,0.60496,0.610296,0.619541,0.627565,0.633617,0.643028,0.644849,0.646871,0.655377,0.661576,0.668091,0.676408,0.680626,0.684486,0.693924,0.70331,0.707336,0.711813,0.720102,0.726267,0.73244,0.740939,0.747134,0.757077,0.764039,0.774089,0.781391,0.791814,0.79776,0.807137,0.81198,0.816665,0.825097,0.830122,0.838238,0.845062,0.8503,0.857706,0.860327,0.866765,0.868701,0.870002,0.877962,0.880618,0.889868,0.893236,0.904043,0.908597,0.919673,0.925844,0.935857,0.943935,0.952176,0.961933,0.968889,0.980357,0.987225,1.},{0,0.0137684,0.0216546,0.0348211,0.0446723,0.0564405,0.0686159,0.0767562,0.0886609,0.0929442,0.0965001,0.108154,0.117897,0.122913,0.13317,0.135703,0.145189,0.148426,0.156767,0.163453,0.168592,0.176315,0.180834,0.184345,0.196693,0.202881,0.216104,0.220759,0.233807,0.235958,0.237725,0.250958,0.254951,0.268055,0.271663,0.281369,0.286945,0.289677,0.303245,0.313562,0.318907,0.32297,0.33493,0.341564,0.353422,0.358052,0.36684,0.372653,0.376506,0.387745,0.397574,0.401611,0.405654,0.414773,0.422491,0.428873,0.436625,0.445433,0.450807,0.459257,0.464605,0.468465,0.47942,0.486963,0.492893,0.498753,0.50258,0.508695,0.509842,0.511199,0.517299,0.523684,0.525873,0.529433,0.533395,0.535125,0.540875,0.54344,0.548311,0.551224,0.555145,0.558318,0.561352,0.564485,0.567283,0.571763,0.57821,0.587229,0.597674,0.601931,0.608288,0.615483,0.619196,0.629204,0.634909,0.642409,0.65004,0.654891,0.6628,0.666358,0.668853,0.678846,0.689445,0.692014,0.694592,0.705395,0.715817,0.718496,0.722442,0.730993,0.735776,0.746097,0.752209,0.762971,0.768952,0.779961,0.785925,0.796273,0.804722,0.810978,0.816904,0.824585,0.8336,0.837312,0.843882,0.847603,0.849484,0.856649,0.860641,0.865593,0.870607,0.875061,0.88167,0.886648,0.895219,0.900858,0.910798,0.916741,0.92761,0.933122,0.944989,0.9494,0.962277,0.965945,0.980369,0.984214,1.},{0,0.0113303,0.0221162,0.0324751,0.0455042,0.0541473,0.0699135,0.0725383,0.0753976,0.0894717,0.100576,0.105114,0.11059,0.118491,0.123828,0.131195,0.137372,0.143269,0.148479,0.156632,0.157903,0.159106,0.16823,0.176999,0.18187,0.195416,0.199921,0.213942,0.220128,0.231602,0.238366,0.248155,0.255314,0.264709,0.272291,0.282002,0.288984,0.300562,0.303007,0.305675,0.317375,0.326656,0.333662,0.343715,0.351163,0.36035,0.36983,0.376494,0.387714,0.390193,0.393644,0.403254,0.410575,0.415311,0.41876,0.426447,0.431656,0.438909,0.443992,0.454112,0.455801,0.457894,0.468702,0.479467,0.484083,0.486147,0.48887,0.497311,0.500253,0.504036,0.506004,0.507154,0.512345,0.516668,0.520227,0.523303,0.528797,0.532654,0.536398,0.540387,0.543054,0.547146,0.548661,0.551382,0.553074,0.554368,0.558086,0.561478,0.564359,0.568303,0.571236,0.579882,0.585382,0.589941,0.599497,0.608604,0.61479,0.62543,0.629275,0.637924,0.641813,0.643829,0.653655,0.658379,0.666632,0.674616,0.67964,0.685704,0.692893,0.700477,0.706187,0.711056,0.720092,0.730041,0.735034,0.746809,0.751045,0.763395,0.767879,0.780042,0.784638,0.797011,0.798846,0.800799,0.812711,0.824082,0.825894,0.827372,0.837208,0.841442,0.848663,0.854029,0.85808,0.864543,0.865364,0.866364,0.873097,0.876502,0.884118,0.889276,0.897791,0.903776,0.913394,0.919181,0.929671,0.935204,0.945765,0.951563,0.961938,0.968365,0.979675,0.986737,1.},{0,0.00883552,0.0224482,0.02995,0.0460689,0.0495418,0.0547859,0.0684914,0.0770429,0.0863181,0.095305,0.101788,0.108674,0.116004,0.125426,0.127524,0.129062,0.13775,0.139714,0.142509,0.14855,0.152028,0.157977,0.163412,0.167521,0.171513,0.179244,0.191122,0.199697,0.210263,0.219959,0.227843,0.23773,0.24403,0.254304,0.259951,0.270862,0.276429,0.286967,0.293957,0.302044,0.311512,0.315234,0.322181,0.328379,0.331392,0.343923,0.345846,0.348586,0.360165,0.365089,0.375923,0.38251,0.391118,0.399016,0.404523,0.411099,0.415647,0.420905,0.424732,0.4268,0.433822,0.436958,0.444677,0.446821,0.451196,0.456957,0.460695,0.468875,0.478196,0.481455,0.49103,0.494594,0.500418,0.503685,0.508615,0.511345,0.515726,0.517086,0.520737,0.523179,0.523816,0.525384,0.531731,0.53513,0.538834,0.541336,0.545142,0.546999,0.551687,0.552264,0.552882,0.557964,0.56112,0.56557,0.570363,0.574385,0.585235,0.586652,0.588026,0.598982,0.604049,0.613658,0.619879,0.628494,0.635925,0.642864,0.651101,0.656755,0.665782,0.670072,0.677519,0.682377,0.685974,0.696153,0.705992,0.710141,0.715405,0.723556,0.729126,0.738375,0.746819,0.754619,0.76364,0.771359,0.780096,0.787751,0.796391,0.803368,0.81468,0.816375,0.81797,0.828385,0.834662,0.84117,0.848025,0.851842,0.856915,0.85972,0.861804,0.866892,0.871831,0.874932,0.882626,0.88539,0.892637,0.897387,0.899669,0.908292,0.912212,0.914187,0.925292,0.930257,0.940113,0.946292,0.955503,0.962261,0.971759,0.979643,0.989915,1.},{0,0.00635268,0.0227337,0.0251249,0.0283077,0.0440541,0.0510436,0.0661642,0.0806874,0.0826821,0.0846379,0.0982103,0.107705,0.112579,0.116992,0.124391,0.131032,0.134968,0.140947,0.145491,0.149805,0.154,0.15813,0.163021,0.166375,0.168314,0.17672,0.186622,0.199207,0.20634,0.21949,0.223303,0.232719,0.237633,0.240042,0.25227,0.256625,0.268329,0.272962,0.284548,0.286835,0.290014,0.299622,0.305614,0.311774,0.316397,0.324787,0.331481,0.340346,0.347002,0.35749,0.362929,0.374439,0.378611,0.389805,0.392505,0.397734,0.40473,0.408069,0.416097,0.421734,0.425065,0.430602,0.432438,0.438573,0.440362,0.447477,0.449934,0.456986,0.460891,0.467335,0.475578,0.477003,0.478826,0.486386,0.490144,0.496906,0.498544,0.500046,0.505257,0.50939,0.512606,0.516985,0.520104,0.524848,0.527388,0.530975,0.535149,0.54095,0.54317,0.548812,0.551226,0.556672,0.560023,0.565268,0.570266,0.574874,0.583663,0.587854,0.598776,0.601632,0.6127,0.616102,0.627851,0.629627,0.63209,0.642632,0.646669,0.656923,0.661392,0.671145,0.675953,0.686011,0.696129,0.700357,0.704473,0.714861,0.725984,0.72922,0.734638,0.743128,0.747561,0.758869,0.764582,0.775486,0.780819,0.791486,0.79642,0.806466,0.812932,0.820334,0.827775,0.83333,0.842435,0.844866,0.848864,0.85447,0.857074,0.862712,0.868115,0.869041,0.87008,0.875291,0.879763,0.883646,0.889959,0.898226,0.900828,0.909976,0.913108,0.921404,0.927858,0.934026,0.943764,0.947879,0.959286,0.961026,0.962652,0.975167,0.97965,0.993076,1.},{0,0.00480246,0.0206969,0.0277977,0.0417989,0.0525401,0.063617,0.0744985,0.0821789,0.0944247,0.0966636,0.0994237,0.110165,0.118221,0.121623,0.12404,0.130618,0.134503,0.13983,0.143099,0.147773,0.150858,0.153671,0.158007,0.160152,0.165616,0.169251,0.174886,0.182195,0.19776,0.200496,0.202821,0.217202,0.223617,0.233853,0.240625,0.249342,0.25681,0.264817,0.272583,0.280414,0.287155,0.295959,0.299159,0.302991,0.309593,0.317445,0.321835,0.331256,0.336486,0.346182,0.353098,0.362147,0.370596,0.378707,0.385319,0.393511,0.399405,0.407148,0.414185,0.418149,0.420615,0.425494,0.428316,0.43092,0.433814,0.436195,0.440843,0.443201,0.448893,0.450745,0.455892,0.457822,0.464213,0.468428,0.473403,0.477858,0.482741,0.48955,0.491149,0.493723,0.49809,0.500213,0.503355,0.505762,0.508237,0.511749,0.514434,0.518811,0.521656,0.528314,0.529996,0.53176,0.538501,0.540757,0.541996,0.548951,0.551775,0.558024,0.561694,0.568393,0.573213,0.582191,0.585986,0.596768,0.599399,0.609531,0.613531,0.620386,0.62882,0.637767,0.643585,0.652961,0.65802,0.667065,0.672907,0.681957,0.689168,0.698917,0.704294,0.710041,0.718379,0.724697,0.733494,0.74416,0.749344,0.761391,0.765514,0.777525,0.781731,0.792878,0.797253,0.807969,0.81059,0.814472,0.822979,0.830374,0.834874,0.837866,0.845924,0.850048,0.857264,0.863349,0.864455,0.865424,0.870058,0.873466,0.875681,0.878278,0.881699,0.886215,0.889929,0.89455,0.900055,0.903827,0.911297,0.913162,0.919646,0.924346,0.928431,0.933969,0.938131,0.941444,0.94957,0.957096,0.963569,0.973588,0.97959,0.993934,0.996442,1.},{0,0.00754639,0.0206451,0.0305803,0.0416005,0.0558622,0.0629233,0.0698027,0.0815002,0.089263,0.0976902,0.1069,0.110803,0.115317,0.121411,0.128577,0.129663,0.130545,0.136718,0.13892,0.145431,0.146332,0.147275,0.154064,0.157923,0.161158,0.164897,0.167672,0.172305,0.175229,0.178532,0.186851,0.199144,0.207804,0.217382,0.227084,0.233668,0.243473,0.248758,0.259299,0.26369,0.274546,0.278703,0.288521,0.293768,0.301029,0.307701,0.311049,0.318786,0.322644,0.332486,0.336079,0.346192,0.349251,0.351294,0.363904,0.368946,0.378056,0.381913,0.384428,0.394416,0.399545,0.407865,0.413449,0.421993,0.425956,0.430394,0.431876,0.435162,0.435873,0.437165,0.440092,0.442852,0.446882,0.451419,0.454257,0.456399,0.46274,0.469193,0.47082,0.472662,0.478416,0.482112,0.486871,0.492541,0.494714,0.497471,0.502212,0.50647,0.509232,0.511217,0.515594,0.519209,0.522124,0.526701,0.527821,0.529198,0.533327,0.536847,0.539147,0.541343,0.544972,0.548586,0.551046,0.554643,0.558527,0.560609,0.562949,0.567438,0.572813,0.574919,0.576603,0.583896,0.588801,0.595399,0.602263,0.608709,0.613406,0.616416,0.621507,0.625064,0.627375,0.629555,0.634664,0.64273,0.648533,0.656548,0.662461,0.672182,0.675638,0.681534,0.689978,0.692998,0.697422,0.709833,0.722007,0.724263,0.726988,0.738251,0.745228,0.754099,0.763023,0.770315,0.779308,0.78637,0.794488,0.801554,0.808955,0.815618,0.824434,0.827585,0.83095,0.838841,0.845831,0.850485,0.856815,0.8616,0.865726,0.868544,0.871602,0.873659,0.876497,0.878557,0.882017,0.883113,0.886882,0.888037,0.888162,0.88884,0.894044,0.897764,0.90135,0.904584,0.909418,0.915319,0.917585,0.923059,0.924765,0.928725,0.933381,0.935405,0.937869,0.943925,0.952142,0.954494,0.95649,0.966234,0.972457,0.981629,0.991741,1.},{0,0.010365,0.0208315,0.0337011,0.0418823,0.0598112,0.0629581,0.0656736,0.0796888,0.0834256,0.084079,0.0875795,0.0984379,0.101914,0.11165,0.117174,0.121639,0.125656,0.129741,0.135011,0.137283,0.142049,0.142945,0.144347,0.148821,0.150619,0.153047,0.15812,0.161796,0.164818,0.168041,0.170968,0.173642,0.177914,0.179316,0.181503,0.185144,0.202102,0.216502,0.221161,0.232503,0.235716,0.237635,0.249643,0.2539,0.264825,0.269829,0.279784,0.284647,0.294308,0.296877,0.300937,0.307462,0.310795,0.317798,0.323129,0.329632,0.336667,0.34317,0.352087,0.358063,0.369778,0.373015,0.376633,0.386793,0.39506,0.399226,0.406926,0.410138,0.412443,0.422317,0.427728,0.437595,0.441846,0.444973,0.448552,0.450288,0.454192,0.455944,0.457357,0.463463,0.466845,0.472398,0.478494,0.479362,0.480155,0.485508,0.491129,0.492039,0.492979,0.498219,0.503621,0.504328,0.505005,0.510014,0.514947,0.515662,0.516363,0.521084,0.52461,0.52683,0.528934,0.532415,0.536322,0.537484,0.538391,0.542176,0.54499,0.546939,0.549536,0.551561,0.553814,0.55639,0.558295,0.561528,0.56485,0.566906,0.571217,0.571782,0.572502,0.577327,0.579399,0.58459,0.588064,0.592831,0.599018,0.600754,0.605662,0.61149,0.612195,0.612796,0.617732,0.621273,0.624052,0.628145,0.634063,0.638337,0.646719,0.649913,0.655854,0.661241,0.664252,0.673753,0.684318,0.689083,0.691721,0.697458,0.70805,0.715306,0.724019,0.736514,0.738207,0.739865,0.752509,0.758429,0.768957,0.77505,0.785037,0.790236,0.800062,0.804249,0.813682,0.81815,0.826399,0.835694,0.837784,0.841487,0.847857,0.849818,0.853201,0.858873,0.860803,0.862371,0.865579,0.86713,0.86831,0.871041,0.874271,0.875075,0.876166,0.879689,0.883701,0.884978,0.886377,0.891139,0.895249,0.898181,0.902066,0.904841,0.906587,0.912048,0.916088,0.919731,0.924588,0.92582,0.927274,0.929606,0.932031,0.93409,0.937865,0.942958,0.945749,0.949207,0.956023,0.966084,0.968312,0.971904,0.98183,0.987489,1.}};


nNow = 257;
Mean[MapThread[calcFitKnots[{#1, nNow}, 3, #2] &, {rowLens - 1, rowParas}]] // AbsoluteTiming

(*10.5sec*)

• Note: no need to share all your actual code. For example calcFitKnots[{107, nNow}, 3, rowParas[[1]]]; // AbsoluteTiming is sufficient to test the speed. – anderstood Mar 29 '17 at 14:57

With the code below, the computation is 50 times faster.

Almost all the computation time is spent in Do. The first idea here is to compute a List denoted by deltaT2 once for all, so that you use efficient list manipulation implementations instead of looping.

Then, after a closer look to your problem, it shows you are simply solving a problem of the form $X=A\delta$ where $A$ is the lower triangular matrix full of ones and $\delta$ is your deltaT. This can be efficiently computed using Accumulate. The key improvement is really the use of Accumulate instead of Do.

calcFitKnots[{m_, n_}, p_, paras_] /; m < n :=
Module[{deltaT, Ubar}, deltaT = Differences@paras;
mu = ConstantArray[0.0, m*n + 1];
deltaT2 = Flatten[Transpose[ConstantArray[deltaT, n]]]/n;
mu = {0}~Join~Accumulate[deltaT2];
Ubar = mu[[1 ;; m*n + 1 ;; m]];
Join[ConstantArray[0.0, p + 1],
MovingAverage[ArrayPad[Ubar, -1], p], ConstantArray[1.0, p + 1]]]


Timing comparison:

Mean[MapThread[
calcFitKnots[{#1, nNow}, 3, #2] &,
{rowLens - 1, rowParas}]]; // RepeatedTiming

(* before: {2.65, Null} *)
(* now: {0.050, Null} *)


Compile might significantly improve the timing.