PHP records program execution time microtime
/** * 记录程序程序时间---只能记录连续的调用改函数 * @param $time_key 记录的key,多次执行可以指定同一个key * @return none 没有返回值,直接获取全局变量$time_arr,如果是在方法中调用需要先global一次 **/ function showExecuTime($time_key = '') { global $time_arr,$time_start,$time_end,$time_num; $time_now = microtime(true); if ( !$time_num ) { $time_num = 0; } $time_num++; if ( $time_num%2 == 1 ) { $time_start = $time_now; } else { $time_end = $time_now; } if ( $time_num %2 == 0 && $time_start && $time_end ) { $time = $time_end - $time_start; if ( $time_key ) { $time_arr[$time_key] += $time; } else { $time_arr[] = $time; } $time_arr['total'] += $time; } } /** * 记录程序程序时间---可以多次交叉的调用 * @param $time_key 记录的key,多次执行可以指定同一个key * @return none 没有返回值,直接获取全局变量$time_arr,如果是在方法中调用需要先global一次 **/ function showExecuTime($time_key = '') { global $time_arr,$time_key_arr,$time_num; $time_now = microtime(true); if ( !$time_key ) { if ( !$time_num ) { $time_num = 0; } $time_num++; $time_key = floor(($time_num+1)/2) - 1; } // 记录本次是开始时间还是结束时间 if ( !isset($time_key_arr[$time_key])) { $time_key_arr[$time_key]['num'] = 0; } $time_key_arr[$time_key]['num']++; if ( $time_key_arr[$time_key]['num']%2 == 1 ) { $time_key_arr[$time_key]['time_start'] = $time_now; } else { $time_key_arr[$time_key]['time_end'] = $time_now; } // 如果连续记录2次,计算结果 if ( $time_key_arr[$time_key]['num'] %2 == 0 && $time_key_arr[$time_key]['time_start'] && $time_key_arr[$time_key]['time_end'] ) { $time = $time_key_arr[$time_key]['time_end'] - $time_key_arr[$time_key]['time_start']; $time_arr[$time_key] += $time; $time_arr['total'] += $time; } } showExecuTime('all'); showExecuTime(); sleep(1); showExecuTime('all');////// sleep(1); showExecuTime(); sleep(1); showExecuTime(); sleep(1); showExecuTime(); showExecuTime('a'); sleep(1); showExecuTime('a'); // showExecuTime('all');////// print_r($time_arr); print_r($time_key_arr);
Copyright Statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.
The above introduces the PHP recording program execution time microtime, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

What is Identity in SQL? Specific code examples are needed. In SQL, Identity is a special data type used to generate auto-incrementing numbers. It is often used to uniquely identify each row of data in a table. The Identity column is often used in conjunction with the primary key column to ensure that each record has a unique identifier. This article will detail how to use Identity and some practical code examples. The basic way to use Identity is to use Identit when creating a table.

1. Function Overview Keyspace notification allows clients to receive events that modify Rediskey changes in some way by subscribing to channels or patterns. All commands that modify key keys. All keys that received the LPUSHkeyvalue[value…] command. All expired keys in the db database. Events are distributed through Redis's subscription and publishing functions (pub/sub), so all clients that support subscription and publishing functions can directly use the keyspace notification function without any modifications. Because the current subscription and publishing functions of Redis adopt a fireandforget strategy, if your program

Today we are mainly going to take a look at the time application method of golang time package. The general rule between the two is that "wall time" is used to tell time, and "monotonic clock" is used to measure time; there are other clock processing methods.

Problems encountered: During the development process, you will encounter keys that need to be deleted in batches according to certain rules, such as login_logID (ID is a variable). Now you need to delete data such as "login_log*", but redis itself only has batch query. Command keys for class key values, but there is no command for batch deletion of a certain class. Solution: Query first, then delete, use xargs to pass parameters (xargs can convert pipe or standard input (stdin) data into command line parameters), execute the query statement first, and then remove the queried key value and the original del parameters. delete. redis-cliKEYSkey* (search condition)|xargsr

An unpatchable Yubico two-factor authentication key vulnerability has broken the security of most Yubikey 5, Security Key, and YubiHSM 2FA devices. The Feitian A22 JavaCard and other devices using Infineon SLB96xx series TPMs are also vulnerable.All

Determine whether a KeyJSONObject exists in JSONObjectjsonObj=newJSONObject();jsonObj.put("version","1.0.0");//version number jsonObj.put("encoding","UTF-8");//encoding method Determine whether the vesion attribute exists in jsonObject jsonObj.has("version");//Return true to check whether the k exists in the json string

There is no command to directly delete keys based on regular expressions in redis, only the delkey1key2... command. However, there is a command to obtain keys through regular expressions in redis: keys "regular expression" can be used to delete keys in batches with the help of the xargs command. Check The key value is passed as a parameter to delredis-clikeys "mailspec*"|xargsdel complete command: [root@localhostredis7001]#redis-cli-h192.169.1.71-p7001-a123456keysem*|x

1. Overview As part of this article, let us start with some problems with the existing Date and CalendarAPI and explore how the new Java8Date and TimeAPI solve these problems. We will also take a look at the core classes in the Java8 time class library, such as LocalDate, LocalTime, LocalDateTime, ZonedDateTime, Period, Duration and their APIs. 2. The problem of thread safety of the old time API (before Java 8)-Date and Calendar classes are not thread-safe, making it difficult for developers to debug concurrency problems of these APIs and need to write additional code to deal with them.
