Cosmological shock waves during structure formation not only play a decisive role for the thermalization of gas in virializing structures but also for the acceleration of relativistic cosmic rays (CRs) through diffusive shock acceleration. We discuss a novel numerical treatment of the physics of cosmic rays in combination with a formalism for identifying and measuring the shock strength on-the-fly during a smoothed particle hydrodynamics simulation. In our methodology, the non-thermal CR population is treated self-consistently in order to assess its dynamical impact on the thermal gas as well as other implications on cosmological observables. Using this formalism, we study the history of the thermalization process in high-resolution hydrodynamic simulations of the Lambda cold dark matter model. Collapsed cosmological structures are surrounded by shocks with high Mach numbers up to 1000, but they play only a minor role in the energy balance of thermalization. However, this finding has important consequences for our understanding of the spatial distribution of CRs in the large-scale structure. In high resolution simulations of galaxy clusters, we find a low contribution of the averaged CR pressure, due to the small acceleration efficiency of lower Mach numbers of flow shocks inside halos and the softer adiabatic index of CRs. However, within cool core regions, the CR pressure reaches equipartition with the thermal pressure leading there to a lower effective adiabatic index and thus to an enhanced compressibility of the central intracluster medium. This effect increases the central density and pressure of the cluster and thus the resulting X-ray emission and the central Sunyaev-Zeldovich flux decrement. The integrated Sunyaev-Zeldovich effect, however, is only slightly changed.