-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cache time representation. #149
Merged
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
bac8735
Cache time representation.
cheatfate 03301c0
Fix compilation issue.
cheatfate 41c8ed6
Add timezone caching and use faster time primitives.
cheatfate 65ccdd1
Fix names and Posix issues.
cheatfate 0a1a458
Fix compilation warnings.
cheatfate 1d21b51
Attempt to optimize a bit.
cheatfate 4759850
New optimization scheme.
cheatfate dde485e
Fix MacOS issue.
cheatfate 3212b34
Make cache thread-safe.
cheatfate 1375da0
Address review comments.
cheatfate 5b28e60
Fix compilation issues.
cheatfate File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
|
||
{.push raises: [].} | ||
|
||
import std/times | ||
export times | ||
|
||
when defined(macos) or defined(macosx) or defined(osx): | ||
from posix import Timeval | ||
proc gettimeofday(tp: var Timeval, tzp: pointer = nil) {. | ||
importc: "gettimeofday", header: "<sys/time.h>", sideEffect.} | ||
elif defined(windows): | ||
type | ||
FILETIME {.final, pure, completeStruct.} = object | ||
dwLowDateTime: uint32 | ||
dwHighDateTime: uint32 | ||
proc getSystemTimeAsFileTime*(lpSystemTimeAsFileTime: var FILETIME) {. | ||
importc: "GetSystemTimeAsFileTime", dynlib: "kernel32", stdcall, | ||
sideEffect.} | ||
else: | ||
const CLOCK_REALTIME_COARSE = 5 | ||
from std/posix import Timespec, Time, clock_gettime | ||
|
||
proc getFastTime*(): times.Time = | ||
when defined(js): | ||
let | ||
millis = newDate().getTime() | ||
seconds = millis div 1_000 | ||
nanos = (millis mod 1_000) * 1_000_000 | ||
initTime(seconds, nanos) | ||
elif defined(macosx): | ||
var a {.noinit.}: Timeval | ||
gettimeofday(a) | ||
initTime(a.tv_sec.int64, int(a.tv_usec) * 1_000) | ||
elif defined(windows): | ||
var f {.noinit.}: FILETIME | ||
getSystemTimeAsFileTime(f) | ||
let tmp = uint64(f.dwLowDateTime) or (uint64(f.dwHighDateTime) shl 32) | ||
fromWinTime(cast[int64](tmp)) | ||
else: | ||
var ts {.noinit.}: Timespec | ||
discard clock_gettime(CLOCK_REALTIME_COARSE, ts) | ||
initTime(int64(ts.tv_sec), int(ts.tv_nsec)) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
etc .. can avoid the memory allocations here