  We characterize the asymptotic performance of nonparametric goodness of fit
testing. The exponential decay rate of the type-II error probability is used as
the asymptotic performance metric, and a test is optimal if it achieves the
maximum rate subject to a constant level constraint on the type-I error
probability. We show that two classes of Maximum Mean Discrepancy (MMD) based
tests attain this optimality on $\mathbb R^d$, while the quadratic-time Kernel
Stein Discrepancy (KSD) based tests achieve the maximum exponential decay rate
under a relaxed level constraint. Under the same performance metric, we proceed
to show that the quadratic-time MMD based two-sample tests are also optimal for
general two-sample problems, provided that kernels are bounded continuous and
characteristic. Key to our approach are Sanov's theorem from large deviation
theory and the weak metrizable properties of the MMD and KSD.
