If functions are listable like Cos, using Range together with Total usually gets met the fastest results.
In[1]:= f[x_] := Cos[x]; (*function*)
n = 75;
I2[f_, a_, b_, n_] := (h = (b - a)/n;
Sum[f[a + (i - 1/2)*h]*h, {i, 1, n}])
I2R[f_, a_, b_, n_] := With[{h = (b - a)/n},
Total[f[a + Range[0.5, n - 0.5, 1.] h] h]
]
{t1, v1} = RepeatedTiming@I2[f, -1.0, 1, n];
{t2, v2} = RepeatedTiming@I2R[f, -1.0, 1, n];
{t1/t2, v1 === v2}
Out[6]= {16.0959, True}