Q:

Speed up matrix evaluation

I would like to define a function func using a combination of built in functions and obtain a similar speed in evaluation as if I evaluated those built in functions by themselves. Currently I am seeing a slow down. An example:
K[x_] = ConstantArray[func[x], {100, 100}];
K2[x_] = ConstantArray[Sin[x], {100, 100}];
func[x_] = Sin[x];
AbsoluteTiming[K[1.]]
AbsoluteTiming[K2[1.]]

{0.00953596, {...}}
{0.00413393, {...}}

The matrix K2 evaluates significantly faster if I replace func by Sin, even though func is defined to be an alias of Sin.
My questions:

What internal process leads to this time difference?
How can I define func such that the times are comparable?

A:

Let's take a smaller example:
Clear[func];
k[x_] = ConstantArray[func[x], 3];
k2[x_] = ConstantArray[Sin[x], 3];
func[x_] = Sin[x];

First compare the DownValues:
Information[k]
Information[k2]

Global`k
k[x_]={func[x],func[x],func[x]}
Global`k2
k2[x_]={Sin[x],Sin[x],Sin[x]}

Now, let's trace what happens:
Trace[k[1.]]

{k[1.],{func[1.],func[1.],func[1.]},{func[1.],Sin[1.],0.841471},{func[1.],Sin[1.],0.841471},{func[1.],Sin[1.],0.841471},{0.841471,0.841471,0.841471}}

Trace[k2[1.]]

{k2[1.],{Sin[1.],Sin[1.],Sin[1.]},{Sin[1.],0.841471},{Sin[1.],0.841471},{Sin[1.],0.841471},{0.841471,0.841471,0.841471}}

For k there is an extra top-level evaluation going from func[1.] to Sin[1.]. This extra evaluation accounts for the timing difference you see.

