Execute inline javascript in wordpress after page fully loaded

I think you should in this case use echo:

function print_script() {

echo '<script type="text/javascript">
window.onload = function () {
    var loadTime = window.performance.timing.domContentLoadedEventEnd-window.performance.timing.navigationStart;
    alert(loadTime);
    console.log(loadTime);
}
        var var1 = <?php echo json_encode('var1'); ?>;
        var var2 = <?php echo json_encode('var2'); ?>;
        var var3 = <?php echo json_encode('var3'); ?>;

</script>';


}
 add_action('wp_print_scripts', 'print_script');

tech