/* More information and Comparison with other models # https://www.statalist.org/forums/forum/general-stata-discussion/general/1475468-benchmarking-stata-to-test-speed-across-computers-and-versions */ *********************************************** clear all set obs 500000 /************************************************** ***************************/ /***** CREATE A DATASET *******************************************/ /************************************************** ***************************/ forv i = 1(1)4 { qui g x`i' = rnormal() } *For Time Series Operations qui g t = _n tsset t qui g z = 0.9*l.x2 + rnormal() if t<=51 *For matrix calculations mata M = rnormal(500,500,0,1) st_matrix("M2",M) end /************************************************** ***************************/ /***** CREATE A STORE MATRIX *******************************************/ /************************************************** ***************************/ mata: st_matrix("R" , J(10,10,0)) matrix colnames R = replace correl regress predict bootstrap /// mvtest xtile expand_drop arfima eigenv /************************************************** ***************************/ /***** TIMER PROGRAMS *******************************************/ /************************************************** ***************************/ capture program drop tstart program tstart, rclass timer clear 1 timer on 1 end capture program drop tend program tend, rclass timer off 1 qui timer list 1 scalar r = r(t1) end /************************************************** ***************************/ /***** PROPORTIONAL TO CORES *******************************************/ /************************************************** ***************************/ qui g y = 0 qui g yt = 0 *replace forv i = 1(1)10 { qui replace yt = 1 + 0.1*x1 -0.25*x2 + 0.4*x3 -0.15*x4 + rnormal() tstart qui replace y = yt tend matrix R[`i',1] = scalar(r) tstart qui correl y x1 x2 x3 x4 tend matrix R[`i',2] = scalar(r) *regress qui reg y x1 x2 x3 x4 // first time is always very slow tstart qui reg y x1 x2 x3 x4 tend matrix R[`i',3] = scalar(r) *predict tstart qui predict cooksd, cooksd tend drop cooksd matrix R[`i',4] = scalar(r) *bootstrap tstart qui bootstrap , reps(25): reg y x1 x2 x3 x4 tend matrix R[`i',5] = scalar(r) } /************************************************** ***************************/ /***** MULTICORE HAS NO EFFECT *****************************************/ /************************************************** ***************************/ forv i = 1(1)10 { *mvtest normality tstart qui mvtest normality y x1 tend matrix R[`i',6] = scalar(r) *xtile tstart qui xtile tempv = y , nq(4) tend capture drop tempv matrix R[`i',7] = scalar(r) * expand, drop if tstart qui expand 2 , g(ex) qui drop if ex==1 tend capture drop ex matrix R[`i',8] = scalar(r) *arfima tstart qui arfima z tend matrix R[`i',9] = scalar(r) *matrix eigenvalues tstart qui matrix eigenvalues re im = M2 tend matrix R[`i',10] = scalar(r) } /************************************************** ***************************/ /***** SUMMARIZE RESULTS *****************************************/ /************************************************** ***************************/ svmat R , names(col) summ replace regress predict correl bootstrap mvtest xtile expand_drop arfima eigenv tabstat replace regress predict correl bootstrap /// mvtest xtile expand_drop arfima eigenv , stats(median mean sd min max) columns(s)