---
title: "计算程序运行的时间"
author: "jaredsun"
date: "2010-12-27T14:25:54Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2010-12-27T14:27:16Z"
id: 852822
url: "https://jaredsun.iteye.com/blog/852822"
---

参考是PHP手册

```php

<?php
/**
* Simple function to replicate PHP 5 behaviour
*/
function microtime_float()
{
    list($usec, $sec) = explode(" ", microtime()); //计算程序运行的时间微秒+时间戳=准确时间
    return ((float)$usec + (float)$sec);
}

$time_start = microtime_float();

// Sleep for a while
usleep(100);

$time_end = microtime_float();
$time = $time_end - $time_start;

echo "Did nothing in $time seconds\n";
?> 



```