This repository has been archived by the owner on Nov 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #87 from kgoodier/review/absolute-time
Avoid use of CFAbsoluteTime as much as possible.
- Loading branch information
Showing
7 changed files
with
220 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// SPDYStopwatch.h | ||
// SPDY | ||
// | ||
// Copyright (c) 2014 Twitter, Inc. All rights reserved. | ||
// Licensed under the Apache License v2.0 | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Created by Kevin Goodier. | ||
// | ||
|
||
typedef double SPDYTimeInterval; | ||
|
||
@interface SPDYStopwatch : NSObject | ||
+ (SPDYTimeInterval)currentSystemTime; | ||
+ (SPDYTimeInterval)currentAbsoluteTime; | ||
- (id)init; | ||
- (void)reset; | ||
- (SPDYTimeInterval)elapsedSeconds; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// | ||
// SPDYStopwatch.m | ||
// SPDY | ||
// | ||
// Copyright (c) 2014 Twitter, Inc. All rights reserved. | ||
// Licensed under the Apache License v2.0 | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Created by Kevin Goodier | ||
// | ||
|
||
#import <mach/mach_time.h> | ||
#import "SPDYStopwatch.h" | ||
|
||
@implementation SPDYStopwatch | ||
{ | ||
SPDYTimeInterval _startTime; | ||
} | ||
|
||
static dispatch_once_t __initTimebase; | ||
static double __machTimebaseToSeconds; | ||
static mach_timebase_info_data_t __machTimebase; | ||
|
||
+ (void)initialize | ||
{ | ||
dispatch_once(&__initTimebase, ^{ | ||
kern_return_t status = mach_timebase_info(&__machTimebase); | ||
// Everything will be 0 if this fails. | ||
if (status != KERN_SUCCESS) { | ||
__machTimebase.numer = 0; | ||
__machTimebase.denom = 1; | ||
} | ||
__machTimebaseToSeconds = (double)__machTimebase.numer / ((double)__machTimebase.denom * 1000000000.0); | ||
}); | ||
} | ||
|
||
+ (SPDYTimeInterval)currentSystemTime | ||
{ | ||
uint64_t now = mach_absolute_time(); | ||
return (SPDYTimeInterval)now * __machTimebaseToSeconds; | ||
} | ||
|
||
+ (SPDYTimeInterval)currentAbsoluteTime | ||
{ | ||
return CFAbsoluteTimeGetCurrent(); | ||
} | ||
|
||
- (id)init | ||
{ | ||
self = [super init]; | ||
if (self) { | ||
_startTime = [SPDYStopwatch currentAbsoluteTime]; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)reset | ||
{ | ||
_startTime = [SPDYStopwatch currentAbsoluteTime]; | ||
} | ||
|
||
- (SPDYTimeInterval)elapsedSeconds | ||
{ | ||
return [SPDYStopwatch currentAbsoluteTime] - _startTime; | ||
} | ||
|
||
@end |
Oops, something went wrong.