The paper proposes a new approach to the design of speed profile for trains concerning time table and energy efficient operation. The method takes into consideration the inclinations of the railway tracks, the speed limits, the nonlinear traction curve and resistances to achieve the energy-efficient speed. The paper demonstrates that by using a predictive optimization approach both punctuality and reduction of energy consumption can be achieved. The proposed method has been tested by simulation based on a real case study. The presented algorithm could be used in drivers' training or as a core algorithm for automatic train operation.