Hey you all I got a time calculation question. I'm attempting to do a lot of PHP and AJAX code appending to HTML. I want to know if my code below will accurately calculate the time of entire code being executed or solely just the PHP code. If it just calculates the PHP, what other code can I add to give me an accurate length of time it takes for the code to execute.

<?php
$before = microtime(true);
/*
    A bunch of PHP Code
*/
?>
<!DOCTYPE html>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script>
  $(function () {
        /*
            A bunch of Jquery Code
        */
    });
</script> 

<body>
    A Lot of HTML Code
</body>
</html>
<?php
$after = microtime(true);
echo ($after-$before);
?>

The PHP code you posted doesn't measure the execution time of the JavaScript. It just measures the time it took the server to parse the page before sending it to the user and well before the user's browser would even start to process the JavaScript.

I'm sure if you search on "JavaScript measure execution time" that you'll find a lot of good advice and sample code.

Member Avatar for diafol

You can also look at the Inspect Element > Network in Chrome browser to give you an idea of how things are working for in practice.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.