In the stabilizer formalism of fault-tolerant quantum computation, stabilizer states serve as classical objects, while magic states (non-stabilizer states) are a kind of quantum resource (called magic resource) for promoting stabilizer circuits to universal quantum computation. In this framework, the T-gate is widely used as a non-Clifford gate which generates magic resource from stabilizer states. A natural question arises as whether the T-gate is in some sense optimal for generating magic resource. We address this issue by employing an intuitive and computable quantifier of magic based on characteristic functions (Weyl transforms) of quantum states. We demonstrate that the qubit T-gate, as well as its qutrit extension, the qutrit T-gate, are indeed optimal for generating magic resource among the class of diagonal unitary operators. Moreover, up to Clifford equivalence, the T-gate is essentially the only gate having such an optimal property. This reveals some intrinsic optimal features of the T-gate. We further compare the T-gate with general unitary gates for generating magic resource.