This paper investigates the control barrier function (CBF) based safety-critical control for continuous nonlinear control affine systems using more efficient online algorithms by the time-varying optimization method. The idea of the algorithms is that when quadratic programming (QP) or other convex optimization algorithms needed in the CBF-based method is not computation affordable, the alternative suboptimal feasible solutions can be obtained more economically. By using the barrier-based interior point method, the constrained CBF-QP problems are transformed into unconstrained ones with suboptimal solutions tracked by two continuous descent-based algorithms. Considering the lag effect of tracking and exploiting the system information, the prediction method is added to the algorithms, which achieves exponential convergence to the time-varying suboptimal solutions. The convergence and robustness of the designed methods as well as the safety criteria of the algorithms are studied theoretically. The effectiveness is illustrated by simulations on the antiswing and obstacle avoidance tasks.