Consider the following:
from dolfin import *
import time
mesh = UnitSquareMesh(10,10)
V = FunctionSpace(mesh, "CG", 1)
u, v = TrialFunction(V), TestFunction(V)
alpha = Constant(1)
a = alpha*inner(u, v)*dx
for i in range(4):
alpha.assign(i)
start = time.time()
A = assemble(a)
end = time.time()
print(end-start, A.norm("frobenius"))
This produces
Calling FFC just-in-time (JIT) compiler, this may take some time.
Calling FFC just-in-time (JIT) compiler, this may take some time.
Calling FFC just-in-time (JIT) compiler, this may take some time.
Calling FFC just-in-time (JIT) compiler, this may take some time.
Calling FFC just-in-time (JIT) compiler, this may take some time.
Calling FFC just-in-time (JIT) compiler, this may take some time.
3.021070957183838 0.0
0.0009584426879882812 0.05157249482255294
0.0006306171417236328 0.10314498964510588
0.0006115436553955078 0.15471748446765718
As you can see, the form is only compiled once.