microtime

Why does my float store in MYSQL as .9999 when it's greater than 1?

淺唱寂寞╮ 提交于 2020-01-03 09:05:12
问题 I'm storing process time in a MySQL database as a float(4,4). $start_time = microtime( TRUE ); // things happen in my script $end_time = microtime( TRUE ); $process_time = $end_time - $start_time; // insert $process time into mysql table $process_time always displays correctly when outputted to the command line, but if it's value is greater than 1, it stores into mysql as .9999. What gives? 回答1: float(4,4) means total 4 digits, 4 of them are after the decimal point. So you have to change to

Microtime() Equivalent for C and C++?

纵然是瞬间 提交于 2019-12-22 04:16:12
问题 I am wondering if there is an equivalent to the PHP function microtime() in C and C++. I looked around but couldn't find a definitive answer. Thanks! 回答1: On Linux, you can use gettimeofday, which should give the same information. In fact, I believe that is the function that PHP uses under the covers. 回答2: There is no exact equivalent to PHP's microtime(), but you could a function with a similar functionality based on the following code: Mac OS X and probably also Linux/Unix #include <sys

How to benchmark efficiency of PHP script

旧巷老猫 提交于 2019-12-16 23:02:36
问题 I want to know what is the best way to benchmark my PHP scripts. Does not matter if a cron job, or webpage or web service. I know i can use microtime but is it really giving me the real time of a PHP script? I want to test and benchmark different functions in PHP that do the same thing. For example, preg_match vs strpos or domdocument vs preg_match or preg_replace vs str_replace` Example of a webpage: <?php // login.php $start_time = microtime(TRUE); session_start(); // do all my logic etc...

MySQL greater than with microtime timestamp

瘦欲@ 提交于 2019-12-11 04:21:57
问题 I have one PHP script inserting rows in a MySQL database. Each row has a field 'created_at' which is filled with the value of the PHP function microtime(true), and inserted as a double. (microtime because I need something more precise than to the second) I have another PHP script that selects rows based on that created_at field. When I go ahead and select like this: SELECT * FROM `ms_voltage` WHERE created_at > 1302775523.51878 I receive a resultset with, as the first row, the row with

php microtime() format value

[亡魂溺海] 提交于 2019-12-10 17:44:29
问题 PHP's microtime() returns something like this: 0.56876200 1385731177 //that's msec sec That value I need it in this format: 1385731177056876200 //this is sec msec without space and dot Currently I'm doing something this: $microtime = microtime(); $microtime_array = explode(" ", $microtime); $value = $microtime_array[1] . str_replace(".", "", $microtime_array[0]); Is there a one line code to achieve this? 回答1: You can do the entire thing in one line using regex: $value = preg_replace('/(0)\.(

Create 3 digit Millisecond with php

谁说胖子不能爱 提交于 2019-12-08 20:46:40
问题 I have 13 digit number and want to create date and time with include milisecond Example code is like this this is my php script $mil = 1328910295939; $seconds = $mil / 1000; $showdate = date('Y:m:d H:i:s', $seconds) ; echo "$showdate"; the result is like this 2012:02:10 15:44:55.xxx ===> xxx is 3 digit miliseconds that i want to show up. and how to include with 3 digit milisecond after H:i:s Please help me..... 回答1: How about something like this? $mil = 1328910295939; function toTimestamp(

DECIMAL length for microtime(true)?

限于喜欢 提交于 2019-12-04 18:49:41
问题 I want to store PHP's microtime as my timestamp in MySQL. I've been told it's best to store it in DECIMAL , but I can't find an ideal size. Does anyone know what the maximum size microtime(true) returns, so I can put that as my data type length? Should I choose variable DECIMAL length? 回答1: tl;dr. Use microtime(false) and store the results in a MySQL bigint as millionths of seconds. Otherwise you have to learn all about floating point arithmetic, which is a big fat hairball. The PHP microtime

DECIMAL length for microtime(true)?

元气小坏坏 提交于 2019-12-03 12:03:48
I want to store PHP's microtime as my timestamp in MySQL. I've been told it's best to store it in DECIMAL , but I can't find an ideal size. Does anyone know what the maximum size microtime(true) returns, so I can put that as my data type length? Should I choose variable DECIMAL length? tl;dr. Use microtime(false) and store the results in a MySQL bigint as millionths of seconds. Otherwise you have to learn all about floating point arithmetic, which is a big fat hairball. The PHP microtime function grabs the Unix timestamp (currently about hex 50eb7c00 or decimal 1,357,609,984) from one system

PHP profiling with microtime(): Negative time?

亡梦爱人 提交于 2019-12-03 08:08:33
问题 For a very simple profiling I use microtime() like this: $now = microtime(); for (...) { // do something echo microtime() - $now; $now = microtime(); } Now, the output of the echo line seems completely random, that is, I expected fluctuations, but I didn't expect negative numbers showing up. However, a typical result contains ~ 1/3 negative numbers. I confirmed this on Solaris (PHP 5.0.x) and WinVista (PHP 5.2.3). What the heck is going on here? Have I invented accidently a time machine? 回答1:

PHP profiling with microtime(): Negative time?

。_饼干妹妹 提交于 2019-12-02 21:40:44
For a very simple profiling I use microtime() like this: $now = microtime(); for (...) { // do something echo microtime() - $now; $now = microtime(); } Now, the output of the echo line seems completely random, that is, I expected fluctuations, but I didn't expect negative numbers showing up. However, a typical result contains ~ 1/3 negative numbers. I confirmed this on Solaris (PHP 5.0.x) and WinVista (PHP 5.2.3). What the heck is going on here? Have I invented accidently a time machine? If you want to do operations on what is returned by microtime, you have to set the "get as float" parameter