f = @(x) sin(x);

N = 10000;
h = 0.01;
x = linspace(0,2*pi,N);

tic
for j = 1:N
    df_for(j) = (f(x(j)+h) -f(x(j)))/h;
end
toc

tic
f1 = f(x);
f2 = f(x+h);
df_vec = (f2-f1)/h;
toc