  Span programs are an important model of quantum computation due to their
tight correspondence with quantum query complexity. For any decision problem
$f$, the minimum complexity of a span program for $f$ is equal, up to a
constant factor, to the quantum query complexity of $f$. Moreover, this
correspondence is constructive. A span program for $f$ with complexity $C$ can
be compiled into a bounded error quantum algorithm for $f$ with query
complexity $O(C)$, and vice versa.
  In this work, we prove an analogous connection for quantum time complexity.
In particular, we show how to convert a quantum algorithm for $f$ with time
complexity $T$ into a span program for $f$ such that it compiles back into a
quantum algorithm for $f$ with time complexity $\widetilde{O}(T)$. While the
query complexity of quantum algorithms obtained from span programs is
well-understood, it is not generally clear how to implement certain
query-independent operations in a time-efficient manner. We show that for span
programs derived from algorithms with a time-efficient implementation, we can
preserve the time efficiency when implementing the span program. This means in
particular that span programs not only fully capture quantum query complexity,
but also quantum time complexity.
  One practical advantage of being able to convert quantum algorithms to span
programs in a way that preserves time complexity is that span programs compose
very nicely. We demonstrate this by improving Ambainis's variable-time quantum
search result using our construction through a span program composition for the
OR function.
