File tree Expand file tree Collapse file tree 1 file changed +17
-4
lines changed Expand file tree Collapse file tree 1 file changed +17
-4
lines changed Original file line number Diff line number Diff line change 1
1
function microtime ( get_as_float ) {
2
2
// discuss at: http://phpjs.org/functions/microtime/
3
3
// original by: Paulo Freitas
4
+ // improved by Dumitru Uzun (http://duzun.me)
4
5
// example 1: timeStamp = microtime(true);
5
6
// example 1: timeStamp > 1000000000 && timeStamp < 2000000000
6
7
// returns 1: true
8
+ // example 2: /^0\.[0-9]{1,6} [0-9]{10,10}$/.test(microtime())
9
+ // returns 2: true
7
10
8
- var now = new Date ( )
9
- . getTime ( ) / 1000 ;
10
- var s = parseInt ( now , 10 ) ;
11
11
12
- return ( get_as_float ) ? now : ( Math . round ( ( now - s ) * 1000 ) / 1000 ) + ' ' + s ;
12
+ if ( typeof performance !== 'undefined' && performance . now ) {
13
+ var now = ( performance . now ( ) + performance . timing . navigationStart ) / 1e3 ;
14
+ if ( get_as_float ) return now ;
15
+
16
+ var s = now | 0 ; // Math.round(now)
17
+ return ( Math . round ( ( now - s ) * 1e6 ) / 1e6 ) + ' ' + s ;
18
+ }
19
+ else {
20
+ var now = ( Date . now ? Date . now ( ) : new Date ( ) . getTime ( ) ) / 1e3 ;
21
+ if ( get_as_float ) return now ;
22
+
23
+ var s = now | 0 ; // Math.round(now)
24
+ return ( Math . round ( ( now - s ) * 1e3 ) / 1e3 ) + ' ' + s ;
25
+ }
13
26
}
You can’t perform that action at this time.
0 commit comments