Questions tagged [microtime]

Anything related to programming languages functions (or other similar facilities) allowing the retrieval of the current time with a resolution in the microseconds range.

Anything related to programming languages functions (or other similar facilities) allowing the retrieval of the current time with a resolution in the microseconds (µs) range.

103 questions
137
votes
15 answers

How to get current time with jQuery

The following returns time in microseconds, for example 4565212462. alert( $.now() ); How do I convert it to a human readable time format, such as (hours:minutes:seconds)?
Relm
  • 6,458
  • 16
  • 56
  • 101
136
votes
8 answers

How to benchmark efficiency of PHP script

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…
eric
  • 2,318
  • 3
  • 16
  • 21
42
votes
1 answer

PHP profiling with microtime(): Negative time?

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…
Boldewyn
  • 75,918
  • 43
  • 139
  • 205
23
votes
3 answers

How to convert microtime() to HH:MM:SS:UU

I was measuring some curl requests and I used microtime(true). The example output would be 3.1745569706 This is 3.1745569706 seconds. I want to convert that to a somewhat more readable format, let's say 00:00:03:17455…
ProDraz
  • 1,255
  • 6
  • 20
  • 40
16
votes
2 answers

php get microtime from date string

I am trying to get the time passed between two datetime strings (including milliseconds) example: $pageTime = strtotime("2012-04-23T16:08:14.9-05:00"); $rowTime = strtotime("2012-04-23T16:08:16.1-05:00"); $timePassed = $rowTime - $pageTime; echo…
slinkhi
  • 819
  • 4
  • 12
  • 30
15
votes
2 answers

How to subtract microtime and display date with milliseconds in php?

How to subtract microtime and display date with milliseconds in php ? For example: I have set end date and time $endtime = 2012-02-21 10:29:59; then I have current date or start date with converted from microtime $starttime = 2012-02-21…
wow development
  • 149
  • 1
  • 1
  • 6
14
votes
6 answers

Can you figure out this PHP timing issue?

Can anyone tell me why when I ran a script with the below contents and then stop it after 5 seconds that I need to divide the elapsed time by 2 to get the correct script execution time? ignore_user_abort(true); set_time_limit(0); $begin_time =…
Abs
  • 51,038
  • 92
  • 260
  • 394
11
votes
2 answers

php microtime explanation

I have this code: $time_sample[] = microtime(true); //start sleep(1); $time_sample[] = microtime(true); //time 1 sleep(2); $time_sample[] = microtime(true); //time 2 sleep(3); $time_sample[] = microtime(true); //time 3 sleep(4); $time_sample[] =…
Adam
  • 1,205
  • 9
  • 20
11
votes
2 answers

Is a timestamp in microseconds always unique?

uniqid() in PHP generates a unique ID based on the current timestamp in microseconds. Is that really a foolproof way to generate a unique ID? Even assuming there's a single user running a single script with a loop generating a timestamp in…
vanamerongen
  • 759
  • 1
  • 10
  • 25
11
votes
4 answers

DECIMAL length for microtime(true)?

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…
user1382306
10
votes
3 answers

Get current timestamp with milliseconds

I want to get current timestamp with milliseconds in PHP something like below, in JavaScript I use Date.now() 1436030635348 I tried something like below: $time = str_replace(".","",microtime(true)); But sometime it is not working properly. Like…
Vishnu
  • 2,132
  • 6
  • 26
  • 52
8
votes
5 answers

Create 3 digit Millisecond with php

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…
Smith
  • 93
  • 1
  • 1
  • 5
8
votes
6 answers

Microtime() Equivalent for C and C++?

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!
user1125551
7
votes
4 answers

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

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…
T. Brian Jones
  • 11,630
  • 19
  • 67
  • 109
7
votes
1 answer

PHP script... goes back in time?

Not really, but I am running into an issue where once in a blue moon while running this script, my time results in a negative number. here is the part of the script where it is happening: public function execute() { $time1 = microtime(); …
grep
  • 3,776
  • 7
  • 38
  • 66
1
2 3 4 5 6 7